Cleaning up some code to make it more robust.
This commit is contained in:
@@ -190,8 +190,8 @@ void handler_read_property_multiple(
|
|||||||
BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||||
{
|
{
|
||||||
int len = 0;
|
int len = 0;
|
||||||
int copy_len = 0;
|
uint16_t copy_len = 0;
|
||||||
int decode_len = 0;
|
uint16_t decode_len = 0;
|
||||||
int pdu_len = 0;
|
int pdu_len = 0;
|
||||||
BACNET_NPDU_DATA npdu_data;
|
BACNET_NPDU_DATA npdu_data;
|
||||||
int bytes_sent;
|
int bytes_sent;
|
||||||
@@ -227,9 +227,11 @@ void handler_read_property_multiple(
|
|||||||
len =
|
len =
|
||||||
rpm_decode_object_id(&service_request[decode_len],
|
rpm_decode_object_id(&service_request[decode_len],
|
||||||
service_len - decode_len, &rpmdata);
|
service_len - decode_len, &rpmdata);
|
||||||
if (len >= 0) { /* Got one so skip to next stage */
|
if (len >= 0) {
|
||||||
|
/* Got one so skip to next stage */
|
||||||
decode_len += len;
|
decode_len += len;
|
||||||
} else { /* bad encoding - skip to error/reject/abort handling */
|
} else {
|
||||||
|
/* bad encoding - skip to error/reject/abort handling */
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "RPM: Bad Encoding.\n");
|
fprintf(stderr, "RPM: Bad Encoding.\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -242,7 +244,7 @@ void handler_read_property_multiple(
|
|||||||
copy_len =
|
copy_len =
|
||||||
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
|
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len,
|
||||||
len, sizeof(Handler_Transmit_Buffer));
|
len, sizeof(Handler_Transmit_Buffer));
|
||||||
if (!copy_len) {
|
if (copy_len == 0) {
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "RPM: Response too big!\r\n");
|
fprintf(stderr, "RPM: Response too big!\r\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -258,7 +260,8 @@ void handler_read_property_multiple(
|
|||||||
len =
|
len =
|
||||||
rpm_decode_object_property(&service_request[decode_len],
|
rpm_decode_object_property(&service_request[decode_len],
|
||||||
service_len - decode_len, &rpmdata);
|
service_len - decode_len, &rpmdata);
|
||||||
if (len < 0) { /* bad encoding - skip to error/reject/abort handling */
|
if (len < 0) {
|
||||||
|
/* bad encoding - skip to error/reject/abort handling */
|
||||||
#if PRINT_ENABLED
|
#if PRINT_ENABLED
|
||||||
fprintf(stderr, "RPM: Bad Encoding.\n");
|
fprintf(stderr, "RPM: Bad Encoding.\n");
|
||||||
#endif
|
#endif
|
||||||
@@ -357,7 +360,6 @@ void handler_read_property_multiple(
|
|||||||
goto RPM_FAILURE;
|
goto RPM_FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decode_is_closing_tag_number(&service_request[decode_len], 1)) {
|
if (decode_is_closing_tag_number(&service_request[decode_len], 1)) {
|
||||||
/* Reached end of property list so cap the result list */
|
/* Reached end of property list so cap the result list */
|
||||||
decode_len++;
|
decode_len++;
|
||||||
@@ -365,7 +367,7 @@ void handler_read_property_multiple(
|
|||||||
copy_len =
|
copy_len =
|
||||||
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0],
|
||||||
apdu_len, len, sizeof(Handler_Transmit_Buffer));
|
apdu_len, len, sizeof(Handler_Transmit_Buffer));
|
||||||
if (!copy_len) {
|
if (copy_len == 0) {
|
||||||
rpmdata.error_code =
|
rpmdata.error_code =
|
||||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||||
error = BACNET_STATUS_ABORT;
|
error = BACNET_STATUS_ABORT;
|
||||||
@@ -376,8 +378,10 @@ void handler_read_property_multiple(
|
|||||||
break; /* finished with this property list */
|
break; /* finished with this property list */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (service_len == decode_len) /* Reached the end so finish up */
|
if (decode_len >= service_len) {
|
||||||
|
/* Reached the end so finish up */
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apdu_len > service_data->max_resp) {
|
if (apdu_len > service_data->max_resp) {
|
||||||
|
|||||||
@@ -282,9 +282,9 @@ int rpm_decode_object_property(
|
|||||||
}
|
}
|
||||||
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
len += decode_enumerated(&apdu[len], len_value_type, &property);
|
||||||
rpmdata->object_property = (BACNET_PROPERTY_ID) property;
|
rpmdata->object_property = (BACNET_PROPERTY_ID) property;
|
||||||
|
/* Assume most probable outcome */
|
||||||
|
rpmdata->array_index = BACNET_ARRAY_ALL;
|
||||||
/* Tag 1: Optional propertyArrayIndex */
|
/* Tag 1: Optional propertyArrayIndex */
|
||||||
rpmdata->array_index = BACNET_ARRAY_ALL; /* Assume most probable outcome */
|
|
||||||
if (IS_CONTEXT_SPECIFIC(apdu[len]) && !IS_CLOSING_TAG(apdu[len])) {
|
if (IS_CONTEXT_SPECIFIC(apdu[len]) && !IS_CLOSING_TAG(apdu[len])) {
|
||||||
option_len =
|
option_len =
|
||||||
(unsigned) decode_tag_number_and_value(&apdu[len], &tag_number,
|
(unsigned) decode_tag_number_and_value(&apdu[len], &tag_number,
|
||||||
|
|||||||
Reference in New Issue
Block a user