Skip to content

Commit cb8144e

Browse files
committed
net: context: Fix the connect check for IPv4
Make sure that we cannot connect to IPv4 multicast or broadcast destination address for a TCP socket. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent 0bec980 commit cb8144e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

subsys/net/ip/net_context.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,13 @@ int net_context_connect(struct net_context *context,
13241324
goto unlock;
13251325
}
13261326

1327-
/* FIXME - Add multicast and broadcast address check */
1327+
if (net_context_get_proto(context) == IPPROTO_TCP &&
1328+
(net_ipv4_is_addr_mcast(&addr4->sin_addr) ||
1329+
net_ipv4_is_addr_bcast(net_context_get_iface(context),
1330+
&addr4->sin_addr))) {
1331+
ret = -EADDRNOTAVAIL;
1332+
goto unlock;
1333+
}
13281334

13291335
memcpy(&addr4->sin_addr, &net_sin(addr)->sin_addr,
13301336
sizeof(struct in_addr));

0 commit comments

Comments
 (0)