Merge pull request #519 from bacnet-stack/fix/rpm-decode-empty-array

Fix decoding empty array of complex type in RPM
This commit is contained in:
Ondřej Hruška
2023-10-23 10:09:32 +02:00
committed by GitHub
+46 -34
View File
@@ -118,40 +118,52 @@ int rpm_ack_decode_service_request(
more than one element to decode */ more than one element to decode */
value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); value = calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE));
rpm_property->value = value; rpm_property->value = value;
while (value && (apdu_len > 0)) {
len = bacapp_decode_known_property(apdu, (unsigned)apdu_len, /* Special case for an empty array - we decode it as null */
value, rpm_object->object_type, if (apdu_len && decode_is_closing_tag_number(apdu, 4)) {
rpm_property->propertyIdentifier); /* NULL value has tag 0, that was already set by calloc */
/* If len == 0 then it's an empty structure, which is OK. */ decoded_len++;
if (len < 0) { apdu_len--;
/* problem decoding */ apdu++;
PERROR("RPM Ack: unable to decode! %s:%s\n", } else {
bactext_object_type_name(rpm_object->object_type), while (value && (apdu_len > 0)) {
bactext_property_name( len = bacapp_decode_known_property(apdu,
rpm_property->propertyIdentifier)); (unsigned)apdu_len, value, rpm_object->object_type,
/* note: caller will free the memory */ rpm_property->propertyIdentifier);
return BACNET_STATUS_ERROR; /* If len == 0 then it's an empty structure, which is
} * OK. */
decoded_len += len; if (len < 0) {
apdu_len -= len; /* problem decoding */
apdu += len; PERROR("RPM Ack: unable to decode! %s:%s\n",
if (apdu_len && decode_is_closing_tag_number(apdu, 4)) { bactext_object_type_name(
decoded_len++; rpm_object->object_type),
apdu_len--; bactext_property_name(
apdu++; rpm_property->propertyIdentifier));
break; /* note: caller will free the memory */
} else if (len > 0) { return BACNET_STATUS_ERROR;
old_value = value; }
value = decoded_len += len;
calloc(1, sizeof(BACNET_APPLICATION_DATA_VALUE)); apdu_len -= len;
old_value->next = value; apdu += len;
} else { if (apdu_len && decode_is_closing_tag_number(apdu, 4)) {
PERROR("RPM Ack: decoded %s:%s len=%d\n", decoded_len++;
bactext_object_type_name(rpm_object->object_type), apdu_len--;
bactext_property_name( apdu++;
rpm_property->propertyIdentifier), break;
len); } else if (len > 0) {
break; old_value = value;
value = calloc(
1, sizeof(BACNET_APPLICATION_DATA_VALUE));
old_value->next = value;
} else {
PERROR("RPM Ack: decoded %s:%s len=%d\n",
bactext_object_type_name(
rpm_object->object_type),
bactext_property_name(
rpm_property->propertyIdentifier),
len);
break;
}
} }
} }
} else if (apdu_len && decode_is_opening_tag_number(apdu, 5)) { } else if (apdu_len && decode_is_opening_tag_number(apdu, 5)) {