From e9249b5b5e66ae0e4eeae9b1360f5ef905c32ab7 Mon Sep 17 00:00:00 2001 From: skarg Date: Tue, 12 Oct 2010 01:17:50 +0000 Subject: [PATCH] Added test for a decoding problem where the stack is unable to decode something, and retrofitted into WriteProperty for each of the demo objects by returning an Error, Out of Range. --- bacnet-stack/demo/gateway/device.c | 7 +- bacnet-stack/demo/object/ao.c | 7 +- bacnet-stack/demo/object/av.c | 7 +- bacnet-stack/demo/object/bi.c | 7 +- bacnet-stack/demo/object/bo.c | 7 +- bacnet-stack/demo/object/bv.c | 7 +- bacnet-stack/demo/object/device.c | 7 +- bacnet-stack/demo/object/lc.c | 7 +- bacnet-stack/demo/object/lo.c | 7 +- bacnet-stack/demo/object/lsp.c | 7 +- bacnet-stack/demo/object/ms-input.c | 7 +- bacnet-stack/demo/object/mso.c | 7 +- bacnet-stack/demo/object/trendlog.c | 8 +- bacnet-stack/ports/at91sam7s/av.c | 7 +- bacnet-stack/ports/at91sam7s/bv.c | 7 +- bacnet-stack/ports/at91sam7s/device.c | 7 +- bacnet-stack/ports/atmega168/av.c | 7 +- bacnet-stack/ports/atmega168/bv.c | 7 +- bacnet-stack/ports/atmega168/device.c | 7 +- bacnet-stack/ports/atmega8/av.c | 7 +- bacnet-stack/ports/atmega8/bv.c | 7 +- bacnet-stack/ports/bdk-atxx4-mstp/av.c | 7 +- bacnet-stack/ports/bdk-atxx4-mstp/bo.c | 7 +- bacnet-stack/ports/bdk-atxx4-mstp/device.c | 7 +- bacnet-stack/ports/pic18f6720/av.c | 7 +- bacnet-stack/ports/pic18f6720/bv.c | 7 +- bacnet-stack/ports/pic18f6720/device.c | 7 +- bacnet-stack/src/bacapp.c | 15 ++-- bacnet-stack/src/bacdcode.c | 99 +++++++++++----------- 29 files changed, 221 insertions(+), 83 deletions(-) diff --git a/bacnet-stack/demo/gateway/device.c b/bacnet-stack/demo/gateway/device.c index 476156e9..842a293d 100644 --- a/bacnet-stack/demo/gateway/device.c +++ b/bacnet-stack/demo/gateway/device.c @@ -1345,7 +1345,12 @@ static bool Device_Write_Property_Local( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: status = diff --git a/bacnet-stack/demo/object/ao.c b/bacnet-stack/demo/object/ao.c index 804e637b..f9beadd0 100644 --- a/bacnet-stack/demo/object/ao.c +++ b/bacnet-stack/demo/object/ao.c @@ -414,7 +414,12 @@ bool Analog_Output_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/demo/object/av.c b/bacnet-stack/demo/object/av.c index 5c24533c..bd18c0be 100644 --- a/bacnet-stack/demo/object/av.c +++ b/bacnet-stack/demo/object/av.c @@ -364,7 +364,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/demo/object/bi.c b/bacnet-stack/demo/object/bi.c index 87cf2c22..4d864f91 100644 --- a/bacnet-stack/demo/object/bi.c +++ b/bacnet-stack/demo/object/bi.c @@ -420,7 +420,12 @@ bool Binary_Input_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: status = diff --git a/bacnet-stack/demo/object/bo.c b/bacnet-stack/demo/object/bo.c index 06d09c7c..63b7ca59 100644 --- a/bacnet-stack/demo/object/bo.c +++ b/bacnet-stack/demo/object/bo.c @@ -357,7 +357,12 @@ bool Binary_Output_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/demo/object/bv.c b/bacnet-stack/demo/object/bv.c index 37f3ba04..1299126e 100644 --- a/bacnet-stack/demo/object/bv.c +++ b/bacnet-stack/demo/object/bv.c @@ -340,7 +340,12 @@ bool Binary_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/demo/object/device.c b/bacnet-stack/demo/object/device.c index daf157d7..30bc632e 100644 --- a/bacnet-stack/demo/object/device.c +++ b/bacnet-stack/demo/object/device.c @@ -1232,8 +1232,13 @@ static bool Device_Write_Property_Local( len = bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: status = diff --git a/bacnet-stack/demo/object/lc.c b/bacnet-stack/demo/object/lc.c index 9e3d5691..bed71017 100644 --- a/bacnet-stack/demo/object/lc.c +++ b/bacnet-stack/demo/object/lc.c @@ -939,7 +939,12 @@ bool Load_Control_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } object_index = Load_Control_Instance_To_Index(wp_data->object_instance); switch (wp_data->object_property) { case PROP_REQUESTED_SHED_LEVEL: diff --git a/bacnet-stack/demo/object/lo.c b/bacnet-stack/demo/object/lo.c index 864b609c..69f4ed7f 100644 --- a/bacnet-stack/demo/object/lo.c +++ b/bacnet-stack/demo/object/lo.c @@ -522,7 +522,12 @@ bool Lighting_Output_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/demo/object/lsp.c b/bacnet-stack/demo/object/lsp.c index d7f1e48c..d8d29a72 100644 --- a/bacnet-stack/demo/object/lsp.c +++ b/bacnet-stack/demo/object/lsp.c @@ -309,7 +309,12 @@ bool Life_Safety_Point_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_MODE: status = diff --git a/bacnet-stack/demo/object/ms-input.c b/bacnet-stack/demo/object/ms-input.c index 31921480..67169128 100644 --- a/bacnet-stack/demo/object/ms-input.c +++ b/bacnet-stack/demo/object/ms-input.c @@ -469,7 +469,12 @@ bool Multistate_Input_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: status = diff --git a/bacnet-stack/demo/object/mso.c b/bacnet-stack/demo/object/mso.c index 5fdaa1f2..d79e1118 100644 --- a/bacnet-stack/demo/object/mso.c +++ b/bacnet-stack/demo/object/mso.c @@ -356,7 +356,12 @@ bool Multistate_Output_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { diff --git a/bacnet-stack/demo/object/trendlog.c b/bacnet-stack/demo/object/trendlog.c index 48632719..fde5ab7a 100644 --- a/bacnet-stack/demo/object/trendlog.c +++ b/bacnet-stack/demo/object/trendlog.c @@ -466,8 +466,12 @@ bool Trend_Log_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ - + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_ENABLE: status = diff --git a/bacnet-stack/ports/at91sam7s/av.c b/bacnet-stack/ports/at91sam7s/av.c index 90bc895f..a50e5061 100644 --- a/bacnet-stack/ports/at91sam7s/av.c +++ b/bacnet-stack/ports/at91sam7s/av.c @@ -342,7 +342,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/ports/at91sam7s/bv.c b/bacnet-stack/ports/at91sam7s/bv.c index c8a1eb7e..bb233c2f 100644 --- a/bacnet-stack/ports/at91sam7s/bv.c +++ b/bacnet-stack/ports/at91sam7s/bv.c @@ -251,7 +251,12 @@ bool Binary_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/ports/at91sam7s/device.c b/bacnet-stack/ports/at91sam7s/device.c index 596a64e5..b74ebe1f 100644 --- a/bacnet-stack/ports/at91sam7s/device.c +++ b/bacnet-stack/ports/at91sam7s/device.c @@ -819,7 +819,12 @@ bool Device_Write_Property_Local( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { diff --git a/bacnet-stack/ports/atmega168/av.c b/bacnet-stack/ports/atmega168/av.c index af379e4f..184b760d 100644 --- a/bacnet-stack/ports/atmega168/av.c +++ b/bacnet-stack/ports/atmega168/av.c @@ -182,7 +182,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/ports/atmega168/bv.c b/bacnet-stack/ports/atmega168/bv.c index fe3f7226..67b8abf7 100644 --- a/bacnet-stack/ports/atmega168/bv.c +++ b/bacnet-stack/ports/atmega168/bv.c @@ -199,7 +199,12 @@ bool Binary_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/ports/atmega168/device.c b/bacnet-stack/ports/atmega168/device.c index 5b7aa6eb..d7eede8b 100644 --- a/bacnet-stack/ports/atmega168/device.c +++ b/bacnet-stack/ports/atmega168/device.c @@ -370,7 +370,12 @@ bool Device_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { diff --git a/bacnet-stack/ports/atmega8/av.c b/bacnet-stack/ports/atmega8/av.c index af379e4f..184b760d 100644 --- a/bacnet-stack/ports/atmega8/av.c +++ b/bacnet-stack/ports/atmega8/av.c @@ -182,7 +182,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/ports/atmega8/bv.c b/bacnet-stack/ports/atmega8/bv.c index fe3f7226..67b8abf7 100644 --- a/bacnet-stack/ports/atmega8/bv.c +++ b/bacnet-stack/ports/atmega8/bv.c @@ -199,7 +199,12 @@ bool Binary_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/av.c b/bacnet-stack/ports/bdk-atxx4-mstp/av.c index 493228bd..5902abee 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/av.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/av.c @@ -332,7 +332,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: status = diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c index f0adbdf7..5f48cc45 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/bo.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/bo.c @@ -393,7 +393,12 @@ bool Binary_Output_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: status = diff --git a/bacnet-stack/ports/bdk-atxx4-mstp/device.c b/bacnet-stack/ports/bdk-atxx4-mstp/device.c index 2ee6d492..fe97405a 100644 --- a/bacnet-stack/ports/bdk-atxx4-mstp/device.c +++ b/bacnet-stack/ports/bdk-atxx4-mstp/device.c @@ -803,7 +803,12 @@ bool Device_Write_Property_Local( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { diff --git a/bacnet-stack/ports/pic18f6720/av.c b/bacnet-stack/ports/pic18f6720/av.c index e495ba00..b9f3b96d 100644 --- a/bacnet-stack/ports/pic18f6720/av.c +++ b/bacnet-stack/ports/pic18f6720/av.c @@ -307,7 +307,12 @@ bool Analog_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_REAL) { diff --git a/bacnet-stack/ports/pic18f6720/bv.c b/bacnet-stack/ports/pic18f6720/bv.c index 657e57f4..d79c192c 100644 --- a/bacnet-stack/ports/pic18f6720/bv.c +++ b/bacnet-stack/ports/pic18f6720/bv.c @@ -218,7 +218,12 @@ bool Binary_Value_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { diff --git a/bacnet-stack/ports/pic18f6720/device.c b/bacnet-stack/ports/pic18f6720/device.c index 95160e87..a37e2bf5 100644 --- a/bacnet-stack/ports/pic18f6720/device.c +++ b/bacnet-stack/ports/pic18f6720/device.c @@ -500,7 +500,12 @@ bool Device_Write_Property( bacapp_decode_application_data(wp_data->application_data, wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ - /* FIXME: len == 0: unable to decode? */ + if (len < 0) { + /* error while decoding - a value larger than we can handle */ + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + return false; + } switch (wp_data->object_property) { case PROP_OBJECT_IDENTIFIER: if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { diff --git a/bacnet-stack/src/bacapp.c b/bacnet-stack/src/bacapp.c index ac3c4a24..7e32c0c1 100644 --- a/bacnet-stack/src/bacapp.c +++ b/bacnet-stack/src/bacapp.c @@ -261,6 +261,7 @@ int bacapp_decode_data( if (len == 0 && tag_data_type != BACNET_APPLICATION_TAG_NULL && tag_data_type != BACNET_APPLICATION_TAG_BOOLEAN) { + /* indicate that we were not able to decode the value */ value->tag = MAX_BACNET_APPLICATION_TAG; } return len; @@ -273,6 +274,7 @@ int bacapp_decode_application_data( { int len = 0; int tag_len = 0; + int decode_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; @@ -286,9 +288,13 @@ int bacapp_decode_application_data( if (tag_len) { len += tag_len; value->tag = tag_number; - len += - bacapp_decode_data(&apdu[len], tag_number, len_value_type, - value); + decode_len = bacapp_decode_data(&apdu[len], tag_number, + len_value_type, value); + if (value->tag != MAX_BACNET_APPLICATION_TAG) { + len += decode_len; + } else { + len = BACNET_STATUS_ERROR; + } } value->next = NULL; } @@ -627,8 +633,7 @@ int bacapp_decode_context_data( len_value_type, value); apdu_len += len; } else { - /* FIXME: what now? */ - apdu_len = 0; + apdu_len = BACNET_STATUS_ERROR; } } value->next = NULL; diff --git a/bacnet-stack/src/bacdcode.c b/bacnet-stack/src/bacdcode.c index d836ca2f..9492e2bd 100644 --- a/bacnet-stack/src/bacdcode.c +++ b/bacnet-stack/src/bacdcode.c @@ -325,7 +325,7 @@ int decode_tag_number( return len; } -/* Same as function above, but will safely fail is packet has been truncated */ +/* Same as function above, but will safely fail if packet has been truncated */ int decode_tag_number_safe( uint8_t * apdu, uint32_t apdu_len_remaining, @@ -351,7 +351,6 @@ int decode_tag_number_safe( return len; } - bool decode_is_opening_tag( uint8_t * apdu) { @@ -580,7 +579,7 @@ int decode_context_boolean2( } len++; } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -694,7 +693,7 @@ int decode_context_bitstring( decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_bitstring(&apdu[len], len_value, bit_string); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -804,7 +803,7 @@ int decode_context_object_id( if (decode_is_context_tag_with_length(&apdu[len], tag_number, &len)) { len += decode_object_id(&apdu[len], object_type, instance); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -977,7 +976,7 @@ int decode_context_octet_string( len += len_value; } } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; @@ -1087,7 +1086,7 @@ int decode_context_character_string( len += len_value; } } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; @@ -1140,7 +1139,7 @@ int decode_context_unsigned( decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_unsigned(&apdu[len], len_value, value); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1246,7 +1245,7 @@ int decode_context_enumerated( decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_enumerated(&apdu[len], len_value, value); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1350,7 +1349,7 @@ int decode_context_signed( decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_signed(&apdu[len], len_value, value); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1581,7 +1580,7 @@ int decode_application_time( len++; len += decode_bacnet_time(&apdu[len], btime); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1597,7 +1596,7 @@ int decode_context_bacnet_time( if (decode_is_context_tag_with_length(&apdu[len], tag_number, &len)) { len += decode_bacnet_time(&apdu[len], btime); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1626,7 +1625,7 @@ int encode_bacnet_date( /* ** Don't try and guess what the user meant here. Just fail */ - return -1; + return BACNET_STATUS_ERROR; } @@ -1715,7 +1714,7 @@ int decode_application_date( len++; len += decode_date(&apdu[len], bdate); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -1730,7 +1729,7 @@ int decode_context_date( if (decode_is_context_tag_with_length(&apdu[len], tag_number, &len)) { len += decode_date(&apdu[len], bdate); } else { - len = -1; + len = BACNET_STATUS_ERROR; } return len; } @@ -2389,7 +2388,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_unsigned(apdu, large_context_tag, in); outLen = decode_context_unsigned(apdu, large_context_tag, &out); @@ -2397,7 +2396,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 16 bit number */ in = 0xdead; @@ -2413,7 +2412,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 8 bit number */ in = 0xde; inLen = encode_context_unsigned(apdu, 10, in); @@ -2428,7 +2427,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 4 bit number */ in = 0xd; inLen = encode_context_unsigned(apdu, 10, in); @@ -2443,7 +2442,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 2 bit number */ in = 0x2; inLen = encode_context_unsigned(apdu, 10, in); @@ -2458,7 +2457,7 @@ void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } @@ -2484,7 +2483,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_signed(apdu, large_context_tag, in); outLen = decode_context_signed(apdu, large_context_tag, &out); @@ -2492,7 +2491,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 16 bit number */ in = 0xdead; @@ -2508,7 +2507,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 8 bit number */ in = 0xde; @@ -2524,7 +2523,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 4 bit number */ in = 0xd; @@ -2540,7 +2539,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 2 bit number */ in = 0x2; @@ -2556,7 +2555,7 @@ void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } @@ -2581,7 +2580,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_enumerated(apdu, large_context_tag, in); outLen = decode_context_enumerated(apdu, large_context_tag, &out); @@ -2589,7 +2588,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 16 bit number */ in = 0xdead; @@ -2605,7 +2604,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 8 bit number */ in = 0xde; inLen = encode_context_enumerated(apdu, 10, in); @@ -2620,7 +2619,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 4 bit number */ in = 0xd; inLen = encode_context_enumerated(apdu, 10, in); @@ -2635,7 +2634,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); /* 2 bit number */ in = 0x2; inLen = encode_context_enumerated(apdu, 10, in); @@ -2650,7 +2649,7 @@ void testEnumeratedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } void testFloatContextDecodes( @@ -2674,7 +2673,7 @@ void testFloatContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_real(apdu, large_context_tag, in); outLen = decode_context_real(apdu, large_context_tag, &out); @@ -2682,7 +2681,7 @@ void testFloatContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); in = 0.0f; inLen = encode_context_real(apdu, 10, in); @@ -2698,7 +2697,7 @@ void testFloatContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } void testDoubleContextDecodes( @@ -2722,7 +2721,7 @@ void testDoubleContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_double(apdu, large_context_tag, in); outLen = decode_context_double(apdu, large_context_tag, &out); @@ -2730,7 +2729,7 @@ void testDoubleContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); in = 0.0; inLen = encode_context_double(apdu, 10, in); @@ -2746,7 +2745,7 @@ void testDoubleContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } void testObjectIDContextDecodes( @@ -2775,7 +2774,7 @@ void testObjectIDContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in_type == out_type); ct_test(pTest, in_id == out_id); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); inLen = encode_context_object_id(apdu, large_context_tag, in_type, in_id); outLen = @@ -2787,7 +2786,7 @@ void testObjectIDContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in_type == out_type); ct_test(pTest, in_id == out_id); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } void testCharacterStringContextDecodes( @@ -2809,7 +2808,7 @@ void testCharacterStringContextDecodes( outLen = decode_context_character_string(apdu, 10, &out); outLen2 = decode_context_character_string(apdu, 9, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.length == out.length); ct_test(pTest, in.encoding == out.encoding); @@ -2820,7 +2819,7 @@ void testCharacterStringContextDecodes( outLen2 = decode_context_character_string(apdu, large_context_tag - 1, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.length == out.length); ct_test(pTest, in.encoding == out.encoding); @@ -2851,7 +2850,7 @@ void testBitStringContextDecodes( outLen = decode_context_bitstring(apdu, 10, &out); outLen2 = decode_context_bitstring(apdu, 9, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.bits_used == out.bits_used); ct_test(pTest, memcmp(in.value, out.value, MAX_BITSTRING_BYTES) == 0); @@ -2860,7 +2859,7 @@ void testBitStringContextDecodes( outLen = decode_context_bitstring(apdu, large_context_tag, &out); outLen2 = decode_context_bitstring(apdu, large_context_tag - 1, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.bits_used == out.bits_used); ct_test(pTest, memcmp(in.value, out.value, MAX_BITSTRING_BYTES) == 0); @@ -2887,7 +2886,7 @@ void testOctetStringContextDecodes( outLen = decode_context_octet_string(apdu, 10, &out); outLen2 = decode_context_octet_string(apdu, 9, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.length == out.length); ct_test(pTest, octetstring_value_same(&in, &out)); @@ -2896,7 +2895,7 @@ void testOctetStringContextDecodes( outLen = decode_context_octet_string(apdu, large_context_tag, &out); outLen2 = decode_context_octet_string(apdu, large_context_tag - 1, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.length == out.length); ct_test(pTest, octetstring_value_same(&in, &out)); @@ -2924,7 +2923,7 @@ void testTimeContextDecodes( outLen = decode_context_bacnet_time(apdu, 10, &out); outLen2 = decode_context_bacnet_time(apdu, 9, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.hour == out.hour); ct_test(pTest, in.hundredths == out.hundredths); @@ -2935,7 +2934,7 @@ void testTimeContextDecodes( outLen = decode_context_bacnet_time(apdu, large_context_tag, &out); outLen2 = decode_context_bacnet_time(apdu, large_context_tag - 1, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.hour == out.hour); ct_test(pTest, in.hundredths == out.hundredths); @@ -2967,7 +2966,7 @@ void testDateContextDecodes( outLen = decode_context_date(apdu, 10, &out); outLen2 = decode_context_date(apdu, 9, &out); - ct_test(pTest, outLen2 == -1); + ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); ct_test(pTest, inLen == outLen); ct_test(pTest, in.day == out.day); ct_test(pTest, in.month == out.month);