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

acassis 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 dd7e7de8e1a net/tcp: skip random port init for fixed-port bind.
dd7e7de8e1a is described below

commit dd7e7de8e1a66939368a5877fc09f4f8c3c84c6b
Author: wangjianyu3 <[email protected]>
AuthorDate: Mon Oct 12 16:47:44 2026 +0800

    net/tcp: skip random port init for fixed-port bind.
    
    tcp_selectport() unconditionally called NET_PORT_RANDOM_INIT()
    (arc4random_buf -> getrandom -> open("/dev/urandom")) even for
    fixed-port binds, which can overflow small stacks. Random port
    init is only needed for the portno == 0 (auto-assign) path.
    
    Assisted-by: Claude:claude-sonnet-5
    Signed-off-by: wangjianyu3 <[email protected]>
---
 net/tcp/tcp_conn.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/tcp/tcp_conn.c b/net/tcp/tcp_conn.c
index 55d0c3b3c44..ae05dafbb50 100644
--- a/net/tcp/tcp_conn.c
+++ b/net/tcp/tcp_conn.c
@@ -510,7 +510,7 @@ int tcp_selectport(uint8_t domain,
 
   /* Generate port base dynamically */
 
-  if (g_last_tcp_port == 0)
+  if (portno == 0 && g_last_tcp_port == 0)
     {
       NET_PORT_RANDOM_INIT(g_last_tcp_port);
     }

Reply via email to