Skip to content

Commit 4ed6ed0

Browse files
lpereirajukkar
authored andcommitted
net: tcp: Be more careful before dereferencing pointer in accept()
The function net_context_accept() was dereferencing context->tcp without asserting it's not NULL, even if the protocol was not TCP. There's a check prior to that to ensure it's a SOCK_STREAM, but that wasn't sufficient to ensure that the pointer wouldn't be dereferenced even if invalid. Change-Id: Ie4f6b9792f6ebb90198ba3a845bb1b83ac450c38 Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
1 parent 777cd07 commit 4ed6ed0

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/yaip/net_context.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,10 +1252,14 @@ int net_context_accept(struct net_context *context,
12521252
}
12531253

12541254
#if defined(CONFIG_NET_TCP)
1255-
if (context->tcp->state != NET_TCP_LISTEN) {
1256-
NET_DBG("Context %p in wrong state %d, should be %d",
1257-
context, context->tcp->state, NET_TCP_LISTEN);
1258-
return -EINVAL;
1255+
if (net_context_get_ip_proto(context) == IPPROTO_TCP) {
1256+
NET_ASSERT(context->tcp);
1257+
1258+
if (context->tcp->state != NET_TCP_LISTEN) {
1259+
NET_DBG("Context %p in wrong state %d, should be %d",
1260+
context, context->tcp->state, NET_TCP_LISTEN);
1261+
return -EINVAL;
1262+
}
12591263
}
12601264

12611265
local_addr.family = net_context_get_family(context);

0 commit comments

Comments
 (0)