Added checking error to prevent crash
When get the error during calculate_string_length,
it can occur crash like below code in oc_alloc_string.
oc_assert(alloc_ret > 0);
So added checking the error and len.
Tested-by: IoTivity Jenkins
@@ -149,6 +149,8 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
}
*err |= cbor_value_calculate_string_length(value, &len);
len++;
+ if (*err != CborNoError || len == 0)
+ return;
oc_alloc_string(&cur->name, len);
*err |= cbor_value_copy_text_string(value, (char *)oc_string(cur->name), &len,
NULL);
@@ -172,6 +174,8 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
case CborByteStringType:
*err |= cbor_value_calculate_string_length(value, &len);
len++;
+ if (*err != CborNoError || len == 0)
+ return;
oc_alloc_string(&cur->value.string, len);
*err |= cbor_value_copy_byte_string(
value, oc_cast(cur->value.string, uint8_t), &len, NULL);
@@ -180,6 +184,8 @@ oc_parse_rep_value(CborValue *value, oc_rep_t **rep, CborError *err)
case CborTextStringType:
*err |= cbor_value_calculate_string_length(value, &len);
len++;
+ if (*err != CborNoError || len == 0)
+ return;
oc_alloc_string(&cur->value.string, len);
*err |= cbor_value_copy_text_string(value, oc_string(cur->value.string),
&len, NULL);
