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

commit 95778c60448bb86c4d4d4445dcdc230c9c021c88
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Nov 2 07:46:47 2026 +0100

    net/local: Give a connection the credentials of the listening socket.
    
    connect() makes the server side of a new stream connection
    (local_alloc_accept()) in the context of the client, and local_alloc()
    fills lc_cred from the caller.  So the server side had the credentials
    of the client, and getsockopt(SO_PEERCRED) on the client returned the
    client itself instead of the server.
    
    Copy the credentials of the listening socket to the server side of the
    connection, so that the client gets the server's process, user and
    group, as on Linux.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/local/local_conn.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/net/local/local_conn.c b/net/local/local_conn.c
index e65f32b8888..16126a58906 100644
--- a/net/local/local_conn.c
+++ b/net/local/local_conn.c
@@ -251,6 +251,14 @@ int local_alloc_accept(FAR struct local_conn_s *server,
   strlcpy(conn->lc_path, server->lc_path, sizeof(conn->lc_path));
   conn->lc_instance_id = client->lc_instance_id;
 
+#ifdef CONFIG_NET_LOCAL_SCM
+  /* connect() makes this end with the client's credentials.  Take the
+   * listener's, so that SO_PEERCRED of the client names the server.
+   */
+
+  conn->lc_cred = server->lc_cred;
+#endif
+
   /* Create the FIFOs needed for the connection */
 
   ret = local_create_fifos(conn, server->lc_rcvsize, client->lc_rcvsize);

Reply via email to