Bug 271335 - www/lighttpd: fix listening on IPv6 and IPv4 addresses
Summary: www/lighttpd: fix listening on IPv6 and IPv4 addresses
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Piotr Kubaj
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-05-09 19:57 UTC by R. Christian McDonald
Modified: 2023-05-25 08:21 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (pkubaj)


Attachments
www/lighttpd: fix listening on IPv6 addresses (1.20 KB, patch)
2023-05-09 19:57 UTC, R. Christian McDonald
no flags Details | Diff
www/lighttpd: fix listening on IPv6 addresses v2 (1.49 KB, patch)
2023-05-15 15:56 UTC, R. Christian McDonald
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description R. Christian McDonald 2023-05-09 19:57:37 UTC
Created attachment 242082 [details]
www/lighttpd: fix listening on IPv6 addresses

getaddrinfo was changed recently to (re)introduce EAI_NODATA and EAI_ADDRFAMILY error cases. These are non-standard error cases with differing semantics across different libc implementations. BSD libc returns EAI_ADDRFAMILY as being synonymous with the nsdispatch error case of similar name NS_ADDRFAMILY. However, GNU libc uses EAI_ADDRFAMILY to report trying to resolve an IPv4 address with an IPv6 hint and vice-versa.

lighttpd abuses this error case by assuming each listen address is first an IPv6 address, falling through to trying IPv4 on error. On systems that define EAI_ADDRFAMILY, the return code is tested to be EAI_ADDRFAMILY before attempting the IPv4 lookup. On platforms that don't define EAI_ADDRFAMILY, this additional test is skipped.

This patch undefines EAI_ADDRFAMILY.
Comment 1 Piotr Kubaj freebsd_committer freebsd_triage 2023-05-09 20:31:36 UTC
Can you report this to upstream?
Comment 2 R. Christian McDonald 2023-05-10 01:53:54 UTC
Yep. I will do that as well
Comment 3 gs-bugs.freebsd.org 2023-05-15 02:31:13 UTC
> This patch undefines EAI_ADDRFAMILY.

Unconditionally undefining EAI_ADDRFAMILY is not something that would be accepted upstream.

Might one of the following patches work better for FreeBSD?

--- a/src/sock_addr.c
+++ b/src/sock_addr.c
@@ -496,7 +496,9 @@ int sock_addr_from_str_hints(sock_addr * const restrict saddr, socklen_t * const
             if (0 != (rc = getaddrinfo(str, NULL, &hints, &res))) {
                 hints.ai_family = AF_INET;
                 if (
-                  #ifdef EAI_ADDRFAMILY
+                  #if defined(EAI_ADDRFAMILY) && defined(EAI_NODATA)
+                    (EAI_ADDRFAMILY == rc || EAI_NODATA == rc) &&
+                  #elif (defined(EAI_ADDRFAMILY)
                     EAI_ADDRFAMILY == rc &&
                   #endif
                     0 == getaddrinfo(str, NULL, &hints, &res)) {

or this?

--- a/src/sock_addr.c
+++ b/src/sock_addr.c
@@ -496,7 +496,7 @@ int sock_addr_from_str_hints(sock_addr * const restrict saddr, socklen_t * const
             if (0 != (rc = getaddrinfo(str, NULL, &hints, &res))) {
                 hints.ai_family = AF_INET;
                 if (
-                  #ifdef EAI_ADDRFAMILY
+                  #if defined(__GLIBC__) && defined(EAI_ADDRFAMILY)
                     EAI_ADDRFAMILY == rc &&
                   #endif
                     0 == getaddrinfo(str, NULL, &hints, &res)) {

I am leaning towards the latter patch.
Comment 4 R. Christian McDonald 2023-05-15 13:17:22 UTC
Sure, if the plan is to upstream to lighttpd that is reasonable.
Comment 5 gs-bugs.freebsd.org 2023-05-15 14:32:16 UTC
This patch is now on lighttpd git master branch and will be part of lighttpd 1.4.71, though no release date is scheduled at the moment (i.e. not soon).

-                  #ifdef EAI_ADDRFAMILY
+                  #if defined(__GLIBC__) && defined(EAI_ADDRFAMILY)

Please do report issues upstream on https://wiki.lighttpd.net/
(I happened to stumble across this issue via search engine.)
Comment 6 R. Christian McDonald 2023-05-15 15:36:14 UTC
Will do, thanks.

Since the next release is not scheduled, I will go ahead submit a revised patch that is aligned with the patch upstream.
Comment 7 R. Christian McDonald 2023-05-15 15:56:15 UTC
Created attachment 242197 [details]
www/lighttpd: fix listening on IPv6 addresses v2
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-05-25 08:19:40 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f75fc16179629b51725274bb82aac362fe6e41e5

commit f75fc16179629b51725274bb82aac362fe6e41e5
Author:     Piotr Kubaj <pkubaj@FreeBSD.org>
AuthorDate: 2023-05-25 08:16:20 +0000
Commit:     Piotr Kubaj <pkubaj@FreeBSD.org>
CommitDate: 2023-05-25 08:18:44 +0000

    www/lighttpd: fix listening on IPv6 addresses

    PR:     271335

 www/lighttpd/Makefile                           |  1 +
 www/lighttpd/files/patch-src_sock__addr.c (new) | 11 +++++++++++
 2 files changed, 12 insertions(+)