Skip to content

Commit 80df24e

Browse files
moonlight83340danieldegrasse
authored andcommitted
net: lib: coap: fix potential null pointer
In coap_well_known_core_get(), move the null check for 'resource' before applying pointer arithmetic ('resource + 1') to avoid undefined behavior when 'resource == NULL'. Signed-off-by: Gaetan Perrot <[email protected]>
1 parent aa4a878 commit 80df24e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

subsys/net/lib/coap/coap_link_format.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,15 @@ int coap_well_known_core_get(struct coap_resource *resource,
695695
struct coap_packet *response,
696696
uint8_t *data, uint16_t data_len)
697697
{
698-
struct coap_resource *resources = resource + 1;
698+
struct coap_resource *resources;
699699
size_t resources_len = 0;
700700

701701
if (resource == NULL) {
702702
return -EINVAL;
703703
}
704704

705+
resources = resource + 1;
706+
705707
while (resources[resources_len].path) {
706708
resources_len++;
707709
}

0 commit comments

Comments
 (0)