-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
coap_resource_parse_observe should return "the observe option value in case of success or negative in case of error." This should be 0 for register and 1 for deregister. However, if a deregister request (1) is received and the observer is already deregistered (e.g. upon a retransmission of a deregister or a stale deregister from a previous session), then coap_resource_parse_observe improperly returns a value of 0 which makes it appear that the client requested a registration instead.
This can cause the response packet to improperly include an Observe option if the response from coap_resource_parse_observe is checked for a value of 0 (subscribe) and can cause caller observation databases to get out of sync. This also violates RFC7641 section 4.1: "The resulting response MUST NOT include an Observe Option."
To fix this, the return from coap_service_remove_observer inside of coap_resource_parse_observe should be checked for a value of 0 (observer didn't exist) and coap_resource_parse_observe should still return 1 ("the observe option value") in that case as documented.
Regression
- This is a regression.
Steps to reproduce
- Run a coap server with a resource supporting observation that calls
coap_resource_parse_observesuch as theobserver.csample for coap. - Send a Observe deregistration command (1) from a client for a token that does not exist.
coap_resource_parse_observereturns 0 (register) instead of 1 (deregister)- The
observer.csample performsr == 0 ? resource->age : 0, soresource->agemay be improperly sent if another observer is present for the same resource.
Relevant log output
Impact
Annoyance – Minor irritation; no significant impact on usability or functionality.
Environment
Bug is present in latest main (2752814)
Additional Context
No response