Secure BACnet decoders and service requests (#1244)
* Secured BACnetAssignedAccessRights decoder. * Secured BACnetPropertyState decoder. * Secured BACnetCredentialAuthenticationFactor decoder. * Secured BACnetEventState change-of-state [1] SEQUENCE decoder. * Secured I-Have-Request service decoder. * Secured Add/Remove ListElement service request decoder. * Secured ConfirmedPrivateTransfer-Request and UnconfirmedPrivateTransfer-Request decoders. * Secured ReadPropertyMultiple-Request and -Ack decoders. * Secured TimeSynchronization-Request decoder. * Secured WritePropertyMultiple service decoders * Secured Trend Log object TL_fetch_property() function. * Secured ReadProperty-Ack decider, * Refactor BACnet time sync recipient handling by moving timesync linked list structure into bacdest where the recipient encoder and decoder already existed. * Secured decoding of BACnetPropertyState. * Secured decoding in the LifeSafetyOperation-Request service. * Secured BACnetAuthenticationFactor decoding in the Credential Data Input object. * Fixed WriteProperty decoder to avoid read buffer overrun. Improved WriteProperty error reporting by adding specific reject codes during decoding similar to WritePropertyMultiple. Deduplicated the WriteProperty handling of abort, reject and error codes. * Added BACNET_STACK_DEPRECATED_DISABLE guards around all of the deprecated decoding functions to ensure they are not used except intentionally for legacy code bases. * Changed version to 1.5.0.rc5 for security fix tracking in branch.
This commit is contained in:
@@ -54,7 +54,7 @@ static void testWritePropertyMultiple(void)
|
||||
BACNET_WRITE_PROPERTY_DATA wp_data = { 0 };
|
||||
uint8_t invoke_id = 1;
|
||||
uint8_t test_invoke_id = 0;
|
||||
int apdu_len = 0;
|
||||
int apdu_len = 0, null_len = 0;
|
||||
int len = 0;
|
||||
uint8_t apdu[480] = { 0 };
|
||||
int offset = 0;
|
||||
@@ -125,8 +125,11 @@ static void testWritePropertyMultiple(void)
|
||||
(3) an optional 'Property Array Index'
|
||||
(4) a 'Property Value'
|
||||
(5) an optional 'Priority' */
|
||||
null_len = wpm_decode_object_property(
|
||||
&apdu[offset], apdu_len - offset, NULL);
|
||||
len = wpm_decode_object_property(
|
||||
&apdu[offset], apdu_len - offset, &wp_data);
|
||||
zassert_equal(len, null_len, NULL);
|
||||
zassert_not_equal(len, 0, NULL);
|
||||
offset += len;
|
||||
printf(
|
||||
@@ -148,6 +151,43 @@ static void testWritePropertyMultiple(void)
|
||||
} while (tag_number != 1);
|
||||
} while (offset < apdu_len);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ZTEST_NEW_API)
|
||||
ZTEST(wp_tests, testWritePropertyMultiple_ACK)
|
||||
#else
|
||||
static void testWritePropertyMultiple_ACK(void)
|
||||
#endif
|
||||
{
|
||||
uint8_t invoke_id = 1;
|
||||
int len = 0, apdu_len = 0, null_len = 0;
|
||||
uint8_t apdu[480] = { 0 };
|
||||
BACNET_WRITE_PROPERTY_DATA data = { 0 }, test_data = { 0 };
|
||||
|
||||
len = wpm_ack_encode_apdu_init(apdu, invoke_id);
|
||||
zassert_equal(len, 3, NULL);
|
||||
zassert_equal(apdu[0], PDU_TYPE_SIMPLE_ACK, NULL);
|
||||
zassert_equal(apdu[1], invoke_id, NULL);
|
||||
|
||||
null_len = wpm_error_ack_encode_apdu(NULL, invoke_id, &data);
|
||||
apdu_len = wpm_error_ack_encode_apdu(apdu, invoke_id, &data);
|
||||
zassert_not_equal(apdu_len, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(apdu_len, null_len, NULL);
|
||||
zassert_equal(apdu[0], PDU_TYPE_ERROR, NULL);
|
||||
zassert_equal(apdu[1], invoke_id, NULL);
|
||||
|
||||
null_len = wpm_error_ack_service_encode(NULL, &data);
|
||||
apdu_len = wpm_error_ack_service_encode(apdu, &data);
|
||||
zassert_not_equal(apdu_len, BACNET_STATUS_ERROR, NULL);
|
||||
len = wpm_error_ack_decode_apdu(apdu, apdu_len, &test_data);
|
||||
zassert_not_equal(len, BACNET_STATUS_ERROR, NULL);
|
||||
zassert_equal(
|
||||
test_data.error_class, data.error_class, "class=%u test-class=%u",
|
||||
test_data.error_class, data.error_class);
|
||||
zassert_equal(
|
||||
test_data.error_code, data.error_code, "code=%u test-code=%u",
|
||||
test_data.error_code, data.error_code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
@@ -157,7 +197,9 @@ ZTEST_SUITE(wp_tests, NULL, NULL, NULL, NULL, NULL);
|
||||
#else
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(wp_tests, ztest_unit_test(testWritePropertyMultiple));
|
||||
ztest_test_suite(
|
||||
wp_tests, ztest_unit_test(testWritePropertyMultiple),
|
||||
ztest_unit_test(testWritePropertyMultiple_ACK));
|
||||
|
||||
ztest_run_test_suite(wp_tests);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user