From 2f8f1475178e161b2538c3613752c4c844522688 Mon Sep 17 00:00:00 2001 From: Joel Bender Date: Mon, 14 Nov 2016 00:18:30 -0500 Subject: [PATCH] trap the invalid array index --- py25/bacpypes/object.py | 12 +++++++++--- py27/bacpypes/object.py | 12 +++++++++--- py34/bacpypes/object.py | 12 +++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/py25/bacpypes/object.py b/py25/bacpypes/object.py index db427d5..170cdb4 100755 --- a/py25/bacpypes/object.py +++ b/py25/bacpypes/object.py @@ -174,8 +174,11 @@ class Property(Logging): raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') if value is not None: - # dive in, the water's fine - value = value[arrayIndex] + try: + # dive in, the water's fine + value = value[arrayIndex] + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # all set return value @@ -228,7 +231,10 @@ class Property(Logging): # seems to be OK, let the array object take over if _debug: Property._debug(" - forwarding to array") - arry[arrayIndex] = value + try: + arry[arrayIndex] = value + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # check for monitors, call each one with the old and new value if is_monitored: diff --git a/py27/bacpypes/object.py b/py27/bacpypes/object.py index 5248d0c..28ff80f 100755 --- a/py27/bacpypes/object.py +++ b/py27/bacpypes/object.py @@ -175,8 +175,11 @@ class Property: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') if value is not None: - # dive in, the water's fine - value = value[arrayIndex] + try: + # dive in, the water's fine + value = value[arrayIndex] + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # all set return value @@ -229,7 +232,10 @@ class Property: # seems to be OK, let the array object take over if _debug: Property._debug(" - forwarding to array") - arry[arrayIndex] = value + try: + arry[arrayIndex] = value + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # check for monitors, call each one with the old and new value if is_monitored: diff --git a/py34/bacpypes/object.py b/py34/bacpypes/object.py index 982f982..130a44d 100755 --- a/py34/bacpypes/object.py +++ b/py34/bacpypes/object.py @@ -175,8 +175,11 @@ class Property: raise ExecutionError(errorClass='property', errorCode='propertyIsNotAnArray') if value is not None: - # dive in, the water's fine - value = value[arrayIndex] + try: + # dive in, the water's fine + value = value[arrayIndex] + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # all set return value @@ -229,7 +232,10 @@ class Property: # seems to be OK, let the array object take over if _debug: Property._debug(" - forwarding to array") - arry[arrayIndex] = value + try: + arry[arrayIndex] = value + except IndexError: + raise ExecutionError(errorClass='property', errorCode='invalidArrayIndex') # check for monitors, call each one with the old and new value if is_monitored: