From 7e544ec637442fdffe6a2342787dc441d78b5b23 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Mon, 27 Feb 2017 21:24:39 -0500 Subject: [PATCH 1/3] trap invlid tag in sub-elements, needs testing --- py25/bacpypes/constructeddata.py | 2 +- py27/bacpypes/constructeddata.py | 2 +- py34/bacpypes/constructeddata.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/py25/bacpypes/constructeddata.py b/py25/bacpypes/constructeddata.py index cea15ea..0db040a 100755 --- a/py25/bacpypes/constructeddata.py +++ b/py25/bacpypes/constructeddata.py @@ -266,7 +266,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError: + except DecodingError, InvalidTag: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: diff --git a/py27/bacpypes/constructeddata.py b/py27/bacpypes/constructeddata.py index 85922f8..82f7641 100755 --- a/py27/bacpypes/constructeddata.py +++ b/py27/bacpypes/constructeddata.py @@ -267,7 +267,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError: + except DecodingError, InvalidTag: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: diff --git a/py34/bacpypes/constructeddata.py b/py34/bacpypes/constructeddata.py index e9c80be..3f98111 100755 --- a/py34/bacpypes/constructeddata.py +++ b/py34/bacpypes/constructeddata.py @@ -267,7 +267,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError: + except DecodingError, InvalidTag: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: From c795e3b0f059e6916ca8691cb6d064e546e4961a Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Mon, 27 Feb 2017 21:35:03 -0500 Subject: [PATCH 2/3] wrong syntax --- py25/bacpypes/constructeddata.py | 2 +- py27/bacpypes/constructeddata.py | 2 +- py34/bacpypes/constructeddata.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/py25/bacpypes/constructeddata.py b/py25/bacpypes/constructeddata.py index 0db040a..2e589b8 100755 --- a/py25/bacpypes/constructeddata.py +++ b/py25/bacpypes/constructeddata.py @@ -266,7 +266,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError, InvalidTag: + except (DecodingError, InvalidTag), err: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: diff --git a/py27/bacpypes/constructeddata.py b/py27/bacpypes/constructeddata.py index 82f7641..75818ad 100755 --- a/py27/bacpypes/constructeddata.py +++ b/py27/bacpypes/constructeddata.py @@ -267,7 +267,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError, InvalidTag: + except (DecodingError, InvalidTag) as err: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: diff --git a/py34/bacpypes/constructeddata.py b/py34/bacpypes/constructeddata.py index 3f98111..45dc228 100755 --- a/py34/bacpypes/constructeddata.py +++ b/py34/bacpypes/constructeddata.py @@ -267,7 +267,7 @@ class Sequence(object): # save the result setattr(self, element.name, value) - except DecodingError, InvalidTag: + except (DecodingError, InvalidTag) as err: # if the context tag was matched, the substructure has to be decoded # correctly. if element.context is None and element.optional: From 836983a1a40290b6d1a4eb7965cc0266e4b15502 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Wed, 8 Mar 2017 08:11:59 -0500 Subject: [PATCH 3/3] check for limits parameter (untested) --- py27/bacpypes/service/device.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/py27/bacpypes/service/device.py b/py27/bacpypes/service/device.py index cc257ae..3defb47 100644 --- a/py27/bacpypes/service/device.py +++ b/py27/bacpypes/service/device.py @@ -287,6 +287,28 @@ class WhoHasIHaveServices(Capability): if _debug: WhoIsIAmServices._debug(" - no local device") return + # if this has limits, check them like Who-Is + if apdu.limits is not None: + # extract the parameters + low_limit = apdu.limits.deviceInstanceRangeLowLimit + high_limit = apdu.limits.deviceInstanceRangeHighLimit + + # check for consistent parameters + if (low_limit is None): + raise MissingRequiredParameter("deviceInstanceRangeLowLimit required") + if (low_limit < 0) or (low_limit > 4194303): + raise ParameterOutOfRange("deviceInstanceRangeLowLimit out of range") + if (high_limit is None): + raise MissingRequiredParameter("deviceInstanceRangeHighLimit required") + if (high_limit < 0) or (high_limit > 4194303): + raise ParameterOutOfRange("deviceInstanceRangeHighLimit out of range") + + # see we should respond + if (self.localDevice.objectIdentifier[1] < low_limit): + return + if (self.localDevice.objectIdentifier[1] > high_limit): + return + # find the object if apdu.object.objectIdentifier is not None: obj = self.objectIdentifier.get(apdu.object.objectIdentifier, None) @@ -294,8 +316,10 @@ class WhoHasIHaveServices(Capability): obj = self.objectName.get(apdu.object.objectName, None) else: raise InconsistentParameters("object identifier or object name required") + + # maybe we don't have it if not obj: - raise ExecutionError(errorClass='object', errorCode='unknownObject') + return # send out the response self.i_have(obj, address=apdu.pduSource)