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

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

commit e37028c4bfd0f36a682c74256d57d13ceca1eab3
Author: zhangshuai39 <[email protected]>
AuthorDate: Fri Jan 30 10:49:21 2026 +0800

    local: Fixed local socket client were overwritten by the server.
    
    Fixed lc_type and lc_proto in the local socket client were overwritten by 
the server.
    
    The client should retain its own type so that it can return the correct 
address format in scenarios such as getsockname, getpeername, and accept.
    
    Signed-off-by: zhangshuai39 <[email protected]>
---
 net/local/local_connect.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/net/local/local_connect.c b/net/local/local_connect.c
index 1266afc7e2c..aabe5b26ba6 100644
--- a/net/local/local_connect.c
+++ b/net/local/local_connect.c
@@ -148,7 +148,19 @@ errout_with_outfd:
 
 errout_with_conn:
   local_release_fifos(conn);
-  client->lc_state = LOCAL_STATE_BOUND;
+  /* Restore client state: if client was unbound, keep it unbound;
+   * if client was bound, restore to bound state.
+   */
+
+  if (client->lc_type == LOCAL_TYPE_UNNAMED)
+    {
+      client->lc_state = LOCAL_STATE_UNBOUND;
+    }
+  else
+    {
+      client->lc_state = LOCAL_STATE_BOUND;
+    }
+
   local_free(conn);
 
   return ret;
@@ -256,16 +268,8 @@ int psock_local_connect(FAR struct socket *psock,
                 conn->lc_type == type && conn->lc_proto == SOCK_STREAM &&
                 strncmp(conn->lc_path, unpath, UNIX_PATH_MAX - 1) == 0)
               {
-                /* Bind the address and protocol */
-
-                client->lc_type  = conn->lc_type;
-                client->lc_proto = conn->lc_proto;
                 client->lc_instance_id = local_generate_instance_id();
 
-                /* The client is now bound to an address */
-
-                client->lc_state = LOCAL_STATE_BOUND;
-
                 /* We have to do more for the SOCK_STREAM family */
 
                 ret = local_stream_connect(client, conn,

Reply via email to