net: Add the check that socket domain is equal to bound address type, 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>
This commit is contained in:
liqinhui 2023-03-27 14:45:23 +08:00 committed by Petro Karashchenko
parent 7dc0d70092
commit a9640bad1a
2 changed files with 18 additions and 0 deletions

View File

@ -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)

View File

@ -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)