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

[PATCH v2 0/3] daemon: fix network address handling bugs

From
SGSebastien Tardif via GitGitGadget <gitgitgadget@gmail.com>
Date
May 27, 2026, 18:18 UTC
Message-ID
<pull.2300.v2.git.git.1779905911.gitgitgadget@gmail.com>
In-Reply-To
<pull.2300.git.git.1778773592.gitgitgadget@gmail.com>
Fix three related issues in daemon.c's network address handling:

IPv6 address corruption in lookup_hostname(): getaddrinfo() is called with AF_UNSPEC hints, so it may return IPv6 results. However, the code unconditionally casts ai_addr to sockaddr_in and passes AF_INET to inet_ntop(). On IPv6-only hosts, this reads from the wrong struct offset, producing garbage IP addresses. Fixed by checking ai_family and handling both AF_INET and AF_INET6.

IPv6 address truncation in ip2str(): 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. Fixed by passing sizeof(ip) instead, and dropping the now-unused len parameter.

NULL pointer in execute() logging: REMOTE_PORT environment variable is used in a format string without a NULL check (only REMOTE_ADDR was checked). If REMOTE_PORT is unset, NULL is passed to printf's %s, which is undefined behavior. Fixed by using a fallback string.

Changes since v1:
 * Split the single patch into three separate commits, one per fix, per
   Patrick's review.
 * Deduplicated the address family handling in lookup_hostname(): instead of
   duplicating the inet_ntop() call for each family, the address pointer is
   extracted into a local void *addr variable first, then inet_ntop() is
   called once, per Patrick's suggestion.
 * The (void *) intermediate cast on ai_addr is used intentionally: C
   guarantees any object pointer round-trips safely through void *, and it
   keeps the per-family blocks shorter than spelling out the full struct
   casts.
 * For the REMOTE_PORT NULL guard: both REMOTE_ADDR and REMOTE_PORT are set
   by the same code path in handle(), so neither should be NULL
   independently. The guard makes the code consistent with the existing
   REMOTE_ADDR check and avoids undefined behavior from printf %s with a
   NULL argument.
 * Die on unexpected address families in lookup_hostname() rather than
   silently leaving addrbuf uninitialized.
Sebastien Tardif (3):
  daemon: fix IPv6 address corruption in lookup_hostname()
  daemon: fix IPv6 address truncation in ip2str()
  daemon: guard NULL REMOTE_PORT in execute() logging
 daemon.c | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
base-commit: 59ff4886a579f4bc91e976fe18590b9ae02c7a08
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2300%2FSebTardif%2Ffix%2Fdaemon-ipv6-and-null-port-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2300/SebTardif/fix/daemon-ipv6-and-null-port-v2
Pull-Request: https://github.com/git/git/pull/2300
Range-diff vs v1:
 1:  b2d8143811 = 1:  b2d8143811 daemon: fix IPv6 address corruption in lookup_hostname()
 2:  5c01ec3cad = 2:  5c01ec3cad daemon: fix IPv6 address truncation in ip2str()
 3:  1b2f9d1a07 ! 3:  e312735716 daemon: guard NULL REMOTE_PORT in execute() logging
     @@ Metadata
       ## Commit message ##
          daemon: guard NULL REMOTE_PORT in execute() logging
      
     -    The REMOTE_PORT environment variable is used in a format string
     -    without a NULL check, while REMOTE_ADDR is checked. If REMOTE_PORT
     -    is unset, NULL is passed to printf's %s, which is undefined behavior.
     +    REMOTE_ADDR and REMOTE_PORT are both set by the same code path in
     +    handle(), so neither should be NULL independently. However, the
     +    existing code checks REMOTE_ADDR before the loginfo() call but not
     +    REMOTE_PORT. If REMOTE_PORT were unset, NULL would be passed to
     +    printf's %s, which is undefined behavior.
      
     -    Add a fallback string for the NULL case.
     +    Add a fallback string for the NULL case, matching the existing
     +    REMOTE_ADDR guard for consistency.
      
          Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
      
-- 
gitgitgadget
Previous: Patrick SteinhardtNext: Sebastien Tardif via GitGitGadget
Message 8 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.