git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] daemon: fix IPv6 address truncation in ip2str()

From
SGSebastien Tardif via GitGitGadget <gitgitgadget@gmail.com>
Date
May 14, 2026, 15:46 UTC
Message-ID
<5c01ec3cadce441cfa48e0499a62e57aa4cc619e.1778773592.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.2300.git.git.1778773592.gitgitgadget@gmail.com>
From: Sebastien Tardif <sebtardif@ncf.ca>

The sockaddr struct size (ai_addrlen) is passed as the output buffer size to inet_ntop(). For IPv6, sizeof(sockaddr_in6) is 28 bytes but INET6_ADDRSTRLEN is 46, so long IPv6 addresses are silently truncated.

Fix this by passing sizeof(ip) instead, which is the actual size of the destination buffer. Drop the now-unused len parameter from ip2str() and update all callers.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
---
 daemon.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/daemon.c b/daemon.c
index 80fa0226d8..103c08d868 100644
--- a/daemon.c
+++ b/daemon.c
@@ -947,7 +947,7 @@ struct socketlist {
 	size_t alloc;
 };
 
-static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
+static const char *ip2str(int family, struct sockaddr *sin)
 {
 #ifdef NO_IPV6
 	static char ip[INET_ADDRSTRLEN];
@@ -958,11 +958,11 @@ static const char *ip2str(int family, struct sockaddr *sin, socklen_t len)
 	switch (family) {
 #ifndef NO_IPV6
 	case AF_INET6:
-		inet_ntop(family, &((struct sockaddr_in6*)sin)->sin6_addr, ip, len);
+		inet_ntop(family, &((struct sockaddr_in6*)sin)->sin6_addr, ip, sizeof(ip));
 		break;
 #endif
 	case AF_INET:
-		inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, len);
+		inet_ntop(family, &((struct sockaddr_in*)sin)->sin_addr, ip, sizeof(ip));
 		break;
 	default:
 		xsnprintf(ip, sizeof(ip), "<unknown>");
@@ -1019,14 +1019,14 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
 
 		if (bind(sockfd, ai->ai_addr, ai->ai_addrlen) < 0) {
 			logerror("Could not bind to %s: %s",
-				 ip2str(ai->ai_family, ai->ai_addr, ai->ai_addrlen),
+				 ip2str(ai->ai_family, ai->ai_addr),
 				 strerror(errno));
 			close(sockfd);
 			continue;	/* not fatal */
 		}
 		if (listen(sockfd, 5) < 0) {
 			logerror("Could not listen to %s: %s",
-				 ip2str(ai->ai_family, ai->ai_addr, ai->ai_addrlen),
+				 ip2str(ai->ai_family, ai->ai_addr),
 				 strerror(errno));
 			close(sockfd);
 			continue;	/* not fatal */
@@ -1080,7 +1080,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
 
 	if ( bind(sockfd, (struct sockaddr *)&sin, sizeof sin) < 0 ) {
 		logerror("Could not bind to %s: %s",
-			 ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
+			 ip2str(AF_INET, (struct sockaddr *)&sin),
 			 strerror(errno));
 		close(sockfd);
 		return 0;
@@ -1088,7 +1088,7 @@ static int setup_named_sock(char *listen_addr, int listen_port, struct socketlis
 
 	if (listen(sockfd, 5) < 0) {
 		logerror("Could not listen to %s: %s",
-			 ip2str(AF_INET, (struct sockaddr *)&sin, sizeof(sin)),
+			 ip2str(AF_INET, (struct sockaddr *)&sin),
 			 strerror(errno));
 		close(sockfd);
 		return 0;
-- 
gitgitgadget
Previous: Junio C HamanoNext: Sebastien Tardif via GitGitGadget
Message 4 of 16 in “daemon: fix network address handling bugs”
  1. 0/3 daemon: fix network address handling bugsSebastien Tardif via GitGitGadget, May 14, 2026
  2. 1/3 daemon: fix IPv6 address corruption in lookup_hostname()Sebastien Tardif via GitGitGadget, May 14, 2026
  3. Junio C HamanoMay 14, 2026
  4. 2/3 daemon: fix IPv6 address truncation in ip2str()Sebastien Tardif via GitGitGadget, May 14, 2026
  5. 3/3 daemon: guard NULL REMOTE_PORT in execute() loggingSebastien Tardif via GitGitGadget, May 14, 2026
  6. Junio C HamanoMay 14, 2026
  7. Patrick SteinhardtMay 15, 2026
  8. 0/3 daemon: fix network address handling bugsSebastien Tardif via GitGitGadget, May 27, 2026
  9. 1/3 daemon: fix IPv6 address corruption in lookup_hostname()Sebastien Tardif via GitGitGadget, May 27, 2026
  10. 2/3 daemon: fix IPv6 address truncation in ip2str()Sebastien Tardif via GitGitGadget, May 27, 2026
  11. 3/3 daemon: guard NULL REMOTE_PORT in execute() loggingSebastien Tardif via GitGitGadget, May 27, 2026
  12. Junio C HamanoMay 27, 2026
  13. 0/3 daemon: fix network address handling bugsSebastien Tardif via GitGitGadget, May 28, 2026
  14. 1/3 daemon: fix IPv6 address corruption in lookup_hostname()Sebastien Tardif via GitGitGadget, May 28, 2026
  15. 2/3 daemon: fix IPv6 address truncation in ip2str()Sebastien Tardif via GitGitGadget, May 28, 2026
  16. 3/3 daemon: guard NULL REMOTE_PORT in execute() loggingSebastien Tardif via GitGitGadget, May 28, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.