Skip to content

Commit 7cfd5a4

Browse files
lpereiraMaureenHelm
authored andcommitted
samples: net: hrpl_border_router: Fix NULL pointer dereference
Null-checking `pkt` before making a call to net_pkt_unref() suggests that it might be NULL, but the pointer is dereferenced before it's checked. Perform the check at the beginning of the function and dereference and drop its reference unconditionally afterwards. Coverity-ID: 178789 Signed-off-by: Leandro Pereira <[email protected]>
1 parent b7ad50b commit 7cfd5a4

File tree

1 file changed

+7
-9
lines changed
  • samples/net/rpl_border_router/src

1 file changed

+7
-9
lines changed

samples/net/rpl_border_router/src/http.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,25 +1682,23 @@ static void http_received(struct http_ctx *ctx,
16821682
const struct sockaddr *dst,
16831683
void *user_data)
16841684
{
1685+
if (!pkt) {
1686+
NET_DBG("Received NULL packet for unknown reason");
1687+
return;
1688+
}
1689+
16851690
if (!status) {
16861691
NET_DBG("Received %d bytes data", net_pkt_appdatalen(pkt));
16871692

16881693
if (!strncmp((char *)net_pkt_appdata(pkt), JSON_COAP_PREFIX,
16891694
sizeof(JSON_COAP_PREFIX) - 1)) {
16901695
handle_coap_request(ctx, pkt, user_data);
16911696
}
1692-
1693-
1694-
if (pkt) {
1695-
net_pkt_unref(pkt);
1696-
}
16971697
} else {
16981698
NET_ERR("Receive error (%d)", status);
1699-
1700-
if (pkt) {
1701-
net_pkt_unref(pkt);
1702-
}
17031699
}
1700+
1701+
net_pkt_unref(pkt);
17041702
}
17051703

17061704
static void http_sent(struct http_ctx *ctx,

0 commit comments

Comments
 (0)