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 -2
View File
@@ -95,6 +95,28 @@ int create_object_encode_service_request(
return apdu_len;
}
/**
* @brief Encode the CreateObject service request
* @param apdu Pointer to the buffer for encoding into
* @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
*/
size_t create_object_service_request_encode(
uint8_t *apdu, size_t apdu_size, BACNET_CREATE_OBJECT_DATA *data)
{
size_t apdu_len = 0; /* total length of the apdu, return value */
apdu_len = create_object_encode_service_request(NULL, data);
if (apdu_len > apdu_size) {
apdu_len = 0;
} else {
apdu_len = create_object_encode_service_request(apdu, data);
}
return apdu_len;
}
/**
* @brief Decode the CreateObject service request
*
@@ -351,7 +373,6 @@ int create_object_error_ack_encode(
return len;
}
#if !BACNET_SVC_SERVER
/**
* @brief Decode a CreateObject-Error ACK APDU
*
@@ -420,4 +441,3 @@ int create_object_error_ack_service_decode(
return apdu_len;
}
#endif