Browse Source

net: lib: coap: Return an error on removing a non-existing observer

If we're parsing a CoAP request with an observe option of '1', but there is
no matching observer, return an error instead of returning a zero.

Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
(cherry picked from commit d5931bae93)
backport-90716-to-v4.0-branch
Pieter De Gendt 1 month ago committed by github-actions[bot]
parent
commit
9d018107e9
  1. 6
      subsys/net/lib/coap/coap_server.c

6
subsys/net/lib/coap/coap_server.c

@ -658,6 +658,12 @@ int coap_resource_parse_observe(struct coap_resource *resource, const struct coa @@ -658,6 +658,12 @@ int coap_resource_parse_observe(struct coap_resource *resource, const struct coa
ret = coap_service_remove_observer(service, resource, addr, token, tkl);
if (ret < 0) {
LOG_WRN("Failed to remove observer (%d)", ret);
goto unlock;
}
if (ret == 0) {
/* Observer not found */
ret = -ENOENT;
}
}

Loading…
Cancel
Save