Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cord_lc: Process truncated reads #20547

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions sys/net/application_layer/cord/lc/cord_lc.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
while (f) {
for (unsigned i = 0; i < f->len; i++) {
clif_attr_t *kv = &(f->array[i]);
if (coap_opt_add_uri_query2(pkt, kv->key, kv->key_len, kv->value, kv->value_len) == -1) {

Check warning on line 144 in sys/net/application_layer/cord/lc/cord_lc.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
return CORD_LC_OVERFLOW;
}
}
Expand Down Expand Up @@ -204,30 +204,39 @@
(void)remote;

thread_flags_t flag = FLAG_NORSC;
size_t full_buf_len = _result_buf_len;
_result_buf_len = 0;

if (memo->state == GCOAP_MEMO_RESP) {
unsigned ct = coap_get_content_type(pdu);
if (ct != COAP_FORMAT_LINK) {
DEBUG("cord_lc: error payload not in link format: %u\n", ct);
goto end;
}
if (pdu->payload_len == 0) {
size_t size = pdu->payload_len;

if (size == 0) {
DEBUG("cord_lc: error empty payload\n");
goto end;
}
memcpy(_result_buf, pdu->payload, pdu->payload_len);
_result_buf_len = pdu->payload_len;
_result_buf[_result_buf_len] = '\0';
if (size >= full_buf_len) {
DEBUG("cord_lc: truncating response from %" PRIuSIZE " to %" PRIuSIZE "\n", size, full_buf_len);

Check warning on line 223 in sys/net/application_layer/cord/lc/cord_lc.c

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/* Not setting FLAG_OVERFLOW: There can still be valid
* .well-known/core lookup data in the usable area, which will be
* used as long as endpoint and resource lookup are both found */
size = full_buf_len;
memcpy(_result_buf, pdu->payload, full_buf_len);
}
else {
memcpy(_result_buf, pdu->payload, size);
}
_result_buf_len = size;
flag = FLAG_SUCCESS;
} else if (memo->state == GCOAP_MEMO_TIMEOUT) {
flag = FLAG_TIMEOUT;
}

end:
if (flag != FLAG_SUCCESS) {
_result_buf = NULL;
_result_buf_len = 0;
}
thread_flags_set(_waiter, flag);
}

Expand Down Expand Up @@ -281,7 +290,9 @@
clif_attr_t attrs[MAX_EXPECTED_ATTRS];
unsigned attrs_used = 0;
size_t parsed_len = 0;
while ((!rd->res_lookif || !rd->ep_lookif) ||
/* Quitting the loop once everything we are interested in was found allows
* us to succeed even if the data was truncated by a too small buffer */
while ((!rd->res_lookif || !rd->ep_lookif) &&
(parsed_len != _result_buf_len)) {

ssize_t ret = clif_decode_link(&lookif, attrs + attrs_used,
Expand Down
Loading