Skip to content

coap_resource_parse_observe returns 0 (register) instead of 1 (deregister) upon a deregister of an unknown observer #90688

@SureshotM6

Description

@SureshotM6

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

  1. Run a coap server with a resource supporting observation that calls coap_resource_parse_observe such as the observer.c sample for coap.
  2. Send a Observe deregistration command (1) from a client for a token that does not exist.
  3. coap_resource_parse_observe returns 0 (register) instead of 1 (deregister)
  4. The observer.c sample performs r == 0 ? resource->age : 0, so resource->age may 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

Metadata

Metadata

Assignees

Labels

area: NetworkingbugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions