Bugfix/service request refactor size check (#553)

* refactor service requests from service header

* add APDU size checking and length feature

* add unit tests to check for length when passing NULL buffer

---------

Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
Steve Karg
2024-01-05 08:59:45 -06:00
committed by GitHub
parent 5ca14e5320
commit bb081d28da
39 changed files with 2614 additions and 1514 deletions
+22
View File
@@ -129,6 +129,28 @@ int awf_service_encode_apdu(uint8_t *apdu, BACNET_ATOMIC_WRITE_FILE_DATA *data)
return apdu_len;
}
/**
* @brief Encode the AtomicWriteFile service request
* @param apdu Pointer to the buffer for encoded values
* @param apdu_size number of bytes available in the buffer
* @param data Pointer to the service data used for encoding values
* @return number of bytes encoded, or zero if unable to encode or too large
*/
int atomicwritefile_service_request_encode(
uint8_t *apdu, size_t apdu_size, BACNET_ATOMIC_WRITE_FILE_DATA *data)
{
size_t apdu_len = 0; /* total length of the apdu, return value */
apdu_len = awf_service_encode_apdu(NULL, data);
if (apdu_len > apdu_size) {
apdu_len = 0;
} else {
apdu_len = awf_service_encode_apdu(apdu, data);
}
return apdu_len;
}
/**
* @brief Encode the AtomicWriteFile service request
* @param apdu Pointer to the buffer for decoding.