Commit d691f56b03 for strongswan.org

commit d691f56b03ab34d08fdd99f05d2313a295e32497
Author: raghu netrakar <raghu@security.bugqore.com>
Date:   Thu Nov 26 15:47:09 2026 +0530

    agent: Fix out-of-bounds write when copying the socket path

    <sys/un.h> doesn't define UNIX_PATH_MAX (it comes from <linux/un.h>), so
    the fallback of 108 bytes is always used.  That matches sun_path on Linux
    but not on macOS and the BSDs, where it is only 104 bytes, so the
    terminator was written four bytes past the end of the sockaddr_un and
    strncpy() was allowed to copy that far.

    Closes strongswan/strongswan#3219

    Fixes: 21c95463211d ("libstrongswan agent plugin to use ssh-agent for RSA signatures")

diff --git a/src/libstrongswan/plugins/agent/agent_private_key.c b/src/libstrongswan/plugins/agent/agent_private_key.c
index 802298cc9b..a6940ef8a3 100644
--- a/src/libstrongswan/plugins/agent/agent_private_key.c
+++ b/src/libstrongswan/plugins/agent/agent_private_key.c
@@ -32,10 +32,6 @@
 #include <utils/chunk.h>
 #include <utils/debug.h>

-#ifndef UNIX_PATH_MAX
-#define UNIX_PATH_MAX 108
-#endif /* UNIX_PATH_MAX */
-
 typedef struct private_agent_private_key_t private_agent_private_key_t;
 typedef enum agent_msg_type_t agent_msg_type_t;

@@ -156,9 +152,10 @@ static bool connect_socket(int fd, char *path)
 {
 	struct sockaddr_un addr;

+	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_UNIX;
-	addr.sun_path[UNIX_PATH_MAX - 1] = '\0';
-	strncpy(addr.sun_path, path, UNIX_PATH_MAX - 1);
+	strncpy(addr.sun_path, path, sizeof(addr.sun_path));
+	addr.sun_path[sizeof(addr.sun_path)-1] = '\0';
 	return connect(fd, (struct sockaddr*)&addr, SUN_LEN(&addr)) == 0;
 }