From 310879a801ec84a557dfdcd04f1a35dfe7ea498c Mon Sep 17 00:00:00 2001 From: "kepler155c@gmail.com" Date: Mon, 20 May 2019 15:19:39 -0400 Subject: [PATCH] sanitize discovery messages --- sys/apps/network/snmp.lua | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/apps/network/snmp.lua b/sys/apps/network/snmp.lua index dcc7bff..0e69a03 100644 --- a/sys/apps/network/snmp.lua +++ b/sys/apps/network/snmp.lua @@ -121,20 +121,26 @@ print('discovery: listening on port 999') Event.on('modem_message', function(_, _, sport, id, info, distance) if sport == 999 and tonumber(id) and type(info) == 'table' then - if not network[id] then - network[id] = { } - end - Util.merge(network[id], info) - network[id].distance = distance - network[id].timestamp = os.clock() + if info.label and info.id and + type(info.label) == 'string' and type(info.id) == 'number' then - if not network[id].label then - network[id].label = 'unknown' - end + if not network[id] then + network[id] = { } + end + Util.merge(network[id], info) + network[id].distance = type(distance) == 'number' and distance + network[id].timestamp = os.clock() - if not network[id].active then - network[id].active = true - os.queueEvent('network_attach', network[id]) + if not network[id].label then + network[id].label = 'unknown' + end + + if not network[id].active then + network[id].active = true + os.queueEvent('network_attach', network[id]) + end + else + print('discovery: Invalid alive message ' .. id) end end end)