This is an automated email from the ASF dual-hosted git repository.

pkarashchenko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new a9640bad1a net: Add the check that socket domain is equal to bound 
address type, when do bind.
a9640bad1a is described below

commit a9640bad1a75997db85ec7cbd0d06c9a0049e68a
Author: liqinhui <[email protected]>
AuthorDate: Mon Mar 27 14:45:23 2023 +0800

    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 <[email protected]>
---
 net/tcp/tcp_conn.c | 9 +++++++++
 net/udp/udp_conn.c | 9 +++++++++
 2 files changed, 18 insertions(+)

diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index e95f2a4ab7..b421d9d453 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -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)
diff --git a/net/udp/udp_conn.c b/net/udp/udp_conn.c
index 5b18064927..7c2a631896 100644
--- a/net/udp/udp_conn.c
+++ b/net/udp/udp_conn.c
@@ -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)

Reply via email to