From 078afaf7d7731d5090c3a78d6aad68907be232e8 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 6 Dec 2019 11:24:30 -0500 Subject: [PATCH] Make SLP more tolerant of malformed data Unrelated devices may present invalid data to SLP queries. Have these conditions better tolerated. --- .../confluent/discovery/protocols/slp.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/confluent_server/confluent/discovery/protocols/slp.py b/confluent_server/confluent/discovery/protocols/slp.py index 09d04691..2ff45a23 100644 --- a/confluent_server/confluent/discovery/protocols/slp.py +++ b/confluent_server/confluent/discovery/protocols/slp.py @@ -84,6 +84,8 @@ def _parse_SrvRply(parsed): :return: """ payload = parsed['payload'] + if len(payload) < 4: + return ecode, ucount = struct.unpack('!HH', bytes(payload[0:4])) if ecode: parsed['errorcode'] = ecode @@ -234,13 +236,20 @@ def _find_srvtype(net, net4, srvtype, addresses, xid): def _grab_rsps(socks, rsps, interval, xidmap): - r, _, _ = select.select(socks, (), (), interval) + r = None + res = select.select(socks, (), (), interval) + if res: + r = res[0] while r: for s in r: (rsp, peer) = s.recvfrom(9000) neighutil.refresh_neigh() _parse_slp_packet(rsp, peer, rsps, xidmap) - r, _, _ = select.select(socks, (), (), interval) + res = select.select(socks, (), (), interval) + if not res: + r = None + else: + r = res[0] @@ -560,7 +569,7 @@ def scan(srvtypes=_slp_services, addresses=None, localonly=False): # now to analyze and flesh out the responses for id in rsps: if 'service:ipmi' in rsps[id]['services']: - if 'service:ipmi://Athena:623' in rsps[id]['urls']: + if 'service:ipmi://Athena:623' in rsps[id].get('urls', ''): rsps[id]['services'] = ['service:thinkagile-storage'] else: continue