Skip to content

Commit

Permalink
net: Add the check that socket domain is equal to bound address type,…
Browse files Browse the repository at this point in the history
… when do bind.

When do socket bind, if the connection domain is not equal to the bound address type, this will cause the stack-buffer-overflow.

Signed-off-by: liqinhui <liqinhui@xiaomi.com>
  • Loading branch information
liqinhuixm authored and pkarashchenko committed May 17, 2023
1 parent 7dc0d70 commit a9640ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions net/tcp/tcp_conn.c
Expand Up @@ -1199,6 +1199,15 @@ FAR struct tcp_conn_s *tcp_alloc_accept(FAR struct net_driver_s *dev,

int tcp_bind(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr)
{
#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
if (conn->domain != addr->sa_family)
{
nerr("ERROR: Invalid address type: %d != %d\n", conn->domain,
addr->sa_family);
return -EINVAL;
}
#endif

#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
Expand Down
9 changes: 9 additions & 0 deletions net/udp/udp_conn.c
Expand Up @@ -807,6 +807,15 @@ int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr)
uint16_t portno;
int ret;

#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
if (conn->domain != addr->sa_family)
{
nerr("ERROR: Invalid address type: %d != %d\n", conn->domain,
addr->sa_family);
return -EINVAL;
}
#endif

#ifdef CONFIG_NET_IPv4
#ifdef CONFIG_NET_IPv6
if (conn->domain == PF_INET)
Expand Down

0 comments on commit a9640ba

Please sign in to comment.