From 11e40a9d61c84235ca82c17dc162ed5288938619 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 16 Jun 2022 18:48:52 +0200 Subject: [PATCH] nanocoap_sock: fix wrong assertion The assertion is a bit overeager. In case of receiving a wrong message ID, we re-try receive without entering the STATE_REQUEST_SEND state again, so it is expected that we get a non-NULL ctx/response from sock_udp_recv_buf(). What this assert should actually check is that we don't get a non-NULL ctx after calling sock_udp_recv_buf() with a non-NULL ctx. So make this explicit to not falsely fail the assertion. --- sys/net/application_layer/nanocoap/sock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/net/application_layer/nanocoap/sock.c b/sys/net/application_layer/nanocoap/sock.c index ae8d0f40b5..6e3a7344b7 100644 --- a/sys/net/application_layer/nanocoap/sock.c +++ b/sys/net/application_layer/nanocoap/sock.c @@ -175,6 +175,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt, case STATE_RESPONSE_OK: DEBUG("nanocoap: waiting for response (timeout: %"PRIu32" µs)\n", _deadline_left_us(deadline)); + const void *old_ctx = ctx; tmp = sock_udp_recv_buf(sock, &payload, &ctx, _deadline_left_us(deadline), NULL); /* sock_udp_recv_buf() is supposed to return multiple packet fragments * when called multiple times with the same context. @@ -183,7 +184,7 @@ ssize_t nanocoap_sock_request_cb(nanocoap_sock_t *sock, coap_pkt_t *pkt, * releases the packet. * This assertion will trigger should the behavior change in the future. */ - if (state != STATE_REQUEST_SEND) { + if (old_ctx) { assert(tmp == 0 && ctx == NULL); } if (tmp == 0) {