Bugfix/deprecate decode tag number and value (#481)

* added or updated secure the BACnet primitive value decoders - the core codecs - named bacnet_x_decode(), bacnet_x_application_decode() and bacnet_x_context_decode where x is one of the 13 BACnet primitive value names.  The updated API includes an APDU size to prevent over-reading of an APDU buffer while decoding.  Improved or added unit test code coverage for the BACnet primitive value decoders.

* marked the insecure decoding API as 'deprecated' which is defined in src/bacnet/basic/sys/platform.h and can be disabled during a build. 

* added secure decoders for BACnetTimeValue, BACnetHostNPort, BACnetTimeStamp, BACnetAddress, and Weekly_Schedule and improved unit test code coverage.

* improved test code coverage for BACnet objects and properties.

* secured AtomicReadFile and AtomicWriteFile service decoders and improved unit test code coverage.

* secured BACnet Error service decoder and improved unit test code coverage.

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2023-09-08 11:39:27 -05:00
committed by GitHub
parent bc8c261153
commit f641aacddb
67 changed files with 6103 additions and 3145 deletions
+23 -1
View File
@@ -26,16 +26,21 @@ static void testAtomicReadFileAckAccess(
uint8_t apdu[480] = { 0 };
int len = 0;
int apdu_len = 0;
int null_len = 0;
uint8_t invoke_id = 128;
uint8_t test_invoke_id = 0;
unsigned int i = 0;
null_len = arf_ack_encode_apdu(NULL, invoke_id, data);
len = arf_ack_encode_apdu(&apdu[0], invoke_id, data);
zassert_not_equal(len, 0, NULL);
zassert_equal(null_len, len, NULL);
apdu_len = len;
null_len = arf_ack_decode_apdu(&apdu[0], apdu_len, NULL, NULL);
len = arf_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
zassert_not_equal(len, -1, NULL);
zassert_true(len > 0, NULL);
zassert_equal(null_len, len, NULL);
zassert_equal(test_data.endOfFile, data->endOfFile, NULL);
zassert_equal(test_data.access, data->access, NULL);
if (test_data.access == FILE_STREAM_ACCESS) {
@@ -65,6 +70,12 @@ static void testAtomicReadFileAckAccess(
octetstring_length(&test_data.fileData[i])), 0, NULL);
}
}
/* test APDU too short */
while (apdu_len) {
apdu_len--;
len = arf_ack_decode_apdu(apdu, apdu_len, NULL, NULL);
zassert_true(len < 0, "len=%d apdu_len=%d", len, apdu_len);
}
}
#if defined(CONFIG_ZTEST_NEW_API)
@@ -102,15 +113,20 @@ static void testAtomicReadFileAccess(BACNET_ATOMIC_READ_FILE_DATA *data)
BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 };
uint8_t apdu[480] = { 0 };
int len = 0;
int null_len = 0;
int apdu_len = 0;
uint8_t invoke_id = 128;
uint8_t test_invoke_id = 0;
null_len = arf_encode_apdu(NULL, invoke_id, data);
len = arf_encode_apdu(&apdu[0], invoke_id, data);
zassert_not_equal(len, 0, NULL);
zassert_equal(len, null_len, NULL);
apdu_len = len;
null_len = arf_decode_apdu(&apdu[0], apdu_len, NULL, NULL);
len = arf_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_data);
zassert_equal(len, null_len, NULL);
zassert_not_equal(len, -1, NULL);
zassert_equal(test_data.object_type, data->object_type, NULL);
zassert_equal(test_data.object_instance, data->object_instance, NULL);
@@ -129,6 +145,12 @@ static void testAtomicReadFileAccess(BACNET_ATOMIC_READ_FILE_DATA *data)
zassert_equal(
test_data.type.record.RecordCount, data->type.record.RecordCount, NULL);
}
/* test APDU too short */
while (apdu_len) {
apdu_len--;
len = arf_decode_apdu(apdu, apdu_len, NULL, NULL);
zassert_true(len < 0, "len=%d apdu_len=%d", len, apdu_len);
}
}
#if defined(CONFIG_ZTEST_NEW_API)