mirror of
https://github.com/obgm/libcoap.git
synced 2026-10-28 05:31:21 +03:00
oscore_cbor.c: Fix coap_persist_observe_add() boundary checks
This commit is contained in:
1 parent
e2463f007f
commit
eadd400b62
2 files changed
+9
-3
No files matched your search
@@ -98,7 +98,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
coap_opt_t *observe;
|
||||
int observe_action;
|
||||
coap_resource_t *r;
|
||||
coap_subscription_t *s;
|
||||
coap_subscription_t *s = NULL;
|
||||
coap_endpoint_t *ep;
|
||||
|
||||
coap_lock_check_locked();
|
||||
@@ -243,6 +243,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
goto oscore_fail;
|
||||
oscore_key_id.s = info_buf;
|
||||
info_buf += oscore_key_id.length;
|
||||
info_buf_len -= oscore_key_id.length;
|
||||
|
||||
/* id_context */
|
||||
ret = oscore_cbor_get_next_element(&info_buf, &info_buf_len);
|
||||
@@ -253,6 +254,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
goto oscore_fail;
|
||||
id_context.s = info_buf;
|
||||
info_buf += id_context.length;
|
||||
info_buf_len -= id_context.length;
|
||||
have_id_context = 1;
|
||||
} else if (ret == CBOR_SIMPLE_VALUE &&
|
||||
oscore_cbor_get_element_size(&info_buf,
|
||||
@@ -268,6 +270,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
goto oscore_fail;
|
||||
aad.s = info_buf;
|
||||
info_buf += aad.length;
|
||||
info_buf_len -= aad.length;
|
||||
have_aad = 1;
|
||||
} else if (ret == CBOR_SIMPLE_VALUE &&
|
||||
oscore_cbor_get_element_size(&info_buf,
|
||||
@@ -284,6 +287,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
goto oscore_fail;
|
||||
partial_iv.s = info_buf;
|
||||
info_buf += partial_iv.length;
|
||||
info_buf_len -= partial_iv.length;
|
||||
have_partial_iv = 1;
|
||||
} else if (ret == CBOR_SIMPLE_VALUE &&
|
||||
oscore_cbor_get_element_size(&info_buf,
|
||||
@@ -300,6 +304,7 @@ coap_persist_observe_add_lkd(coap_context_t *context,
|
||||
goto oscore_fail;
|
||||
nonce.s = info_buf;
|
||||
info_buf += nonce.length;
|
||||
info_buf_len -= nonce.length;
|
||||
have_nonce = 1;
|
||||
} else if (ret == CBOR_SIMPLE_VALUE &&
|
||||
oscore_cbor_get_element_size(&info_buf,
|
||||
|
||||
@@ -279,8 +279,9 @@ oscore_cbor_get_element_size(const uint8_t **buffer, size_t *buf_len) {
|
||||
uint8_t
|
||||
oscore_cbor_elem_contained(const uint8_t *data, size_t *buf_len, uint8_t *end) {
|
||||
const uint8_t *buf = data;
|
||||
const uint8_t *last = data + oscore_cbor_get_element_size(&buf, buf_len);
|
||||
if (last > end) {
|
||||
uint64_t size = oscore_cbor_get_element_size(&buf, buf_len);
|
||||
|
||||
if (size > 0xffffffff || data + size > end) {
|
||||
coap_log_err("oscore_cbor_elem_contained returns 1 \n");
|
||||
return 1;
|
||||
} else
|
||||
|
||||
Reference in new issue
Block a user