Reject malformed 3PE query metadata results earlier in AS API handling code

This commit is contained in:
Paul "LeoNerd" Evans 2016-09-09 15:07:04 +01:00
parent f25d74f69c
commit ed44c475d8
2 changed files with 15 additions and 11 deletions

View File

@ -162,11 +162,19 @@ class ApplicationServiceApi(SimpleHttpClient):
urllib.quote(protocol)
)
try:
defer.returnValue((yield self.get_json(uri, {})))
info = yield self.get_json(uri, {})
# Ignore any result that doesn't contain an "instances" list
if "instances" not in info:
defer.returnValue(None)
if not isinstance(info["instances"], list):
defer.returnValue(None)
defer.returnValue(info)
except Exception as ex:
logger.warning("query_3pe_protocol to %s threw exception %s",
uri, ex)
defer.returnValue({})
defer.returnValue(None)
key = (service.id, protocol)
return self.protocol_meta_cache.get(key) or (

View File

@ -186,16 +186,12 @@ class ApplicationServicesHandler(object):
if only_protocol is not None and p != only_protocol:
continue
info = yield self.appservice_api.get_3pe_protocol(s, p)
# Ignore any result that doesn't contain an "instances" list
if "instances" not in info:
continue
if not isinstance(info["instances"], list):
continue
if p not in protocols:
protocols[p] = []
info = yield self.appservice_api.get_3pe_protocol(s, p)
if info is not None:
protocols[p].append(info)
def _merge_instances(infos):