Skip to content

net: lib: coap: client: Invalid path pointer #97115

@pdgendt

Description

@pdgendt

Describe the bug

Using the CoAP client to make a request using a path located for example on the stack, it is later used to evaluate matching requests.

Consider the following snippets:

static int foo_get(uint16_t id)
{
	/* Construct my dynamic path */
	char path[sizeof("foo/xxxxx")];
	snprintf(path, sizeof(path), "foo/%d", id);

	/* Do request */
	struct coap_client_request req = {
		.method = COAP_METHOD_GET,
		.path = path, /* <--------- A stack buffer */
		.cb = foo_cb,
	};
	/* Doing the request is fine because the CoAP packet is constructed
	 * and the path is converted to CoAP options */
	return coap_client_req(&client, 0, &dst_address, &req, NULL));
}

If at any point in the lifetime of the request a call is done to coap_client_cancel_request or coap_client_cancel_requests it will compare an internally stored copy of the pointer here:

if (a->path && b->path && strcmp(a->path, b->path) != 0) {
return false;
}

Resulting in calling strcmp with an invalid pointer.

Regression

  • This is a regression.

Steps to reproduce

No response

Relevant log output

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

No response

Additional Context

No response

Metadata

Metadata

Assignees

Labels

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

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions