From 64e5a31b61b7f55fc5fd94461a4977e7551e197f Mon Sep 17 00:00:00 2001 From: Robert Lubos Date: Mon, 20 Jan 2025 13:16:42 +0100 Subject: [PATCH] net: coap: Fix coap_packet_is_request() check for empty code Empty code was incorrectly matched as a request, fix that. Align coap_handle_request_len() function to behave as documented in the API documentation - in case of invalid request code (which is also the case for empty code) -ENOTSUP Should be returned. Signed-off-by: Robert Lubos --- subsys/net/lib/coap/coap.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subsys/net/lib/coap/coap.c b/subsys/net/lib/coap/coap.c index cec234fcb9b..99c2e47f9cb 100644 --- a/subsys/net/lib/coap/coap.c +++ b/subsys/net/lib/coap/coap.c @@ -1172,7 +1172,7 @@ bool coap_packet_is_request(const struct coap_packet *cpkt) { uint8_t code = coap_header_get_code(cpkt); - return !(code & ~COAP_REQUEST_MASK); + return (code != COAP_CODE_EMPTY) && !(code & ~COAP_REQUEST_MASK); } int coap_handle_request_len(struct coap_packet *cpkt, @@ -1183,7 +1183,7 @@ int coap_handle_request_len(struct coap_packet *cpkt, struct sockaddr *addr, socklen_t addr_len) { if (!coap_packet_is_request(cpkt)) { - return 0; + return -ENOTSUP; } /* FIXME: deal with hierarchical resources */