From: Iain Sandoe <iains.gcc@gmail.com>
To: gcc-patches@gcc.gnu.org
Cc: jason@redhat.com, nathan@acm.org
Subject: [PATCH 2/2] c++tools: Work around a BSD bug in getaddrinfo().
Date: Sun, 13 Mar 2022 23:16:03 +0000 [thread overview]
Message-ID: <20220313231603.12480-1-iain@sandoe.co.uk> (raw)
Some versions of the BSD getaddrinfo() call do not work with the specific
input of "0" for the servname entry (a segv results). Since we are making
the call with a dummy port number, the value is actually not important, other
than it should be in range. Work around the BSD bug by using "1" instead.
tested on powerpc,i686-darwin9, x86-64-darwin10,17,20
powerpc64le,powerpc64,x86_64-linux-gnu,
OK for master?
eventual backports?
thanks
Iain
Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
c++tools/ChangeLog:
* server.cc (accept_from): Use "1" as the dummy port number.
---
c++tools/server.cc | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/c++tools/server.cc b/c++tools/server.cc
index 8c6ad314886..00154a05925 100644
--- a/c++tools/server.cc
+++ b/c++tools/server.cc
@@ -360,7 +360,11 @@ accept_from (char *arg ATTRIBUTE_UNUSED)
hints.ai_next = NULL;
struct addrinfo *addrs = NULL;
- if (int e = getaddrinfo (slash == arg ? NULL : arg, "0", &hints, &addrs))
+ /* getaddrinfo requires either hostname or servname to be non-null, so that we must
+ set a port number (to cover the case that the string passed contains just /NN).
+ Use an arbitrary in-range port number, but avoiding "0" which triggers a bug on
+ some BSD variants. */
+ if (int e = getaddrinfo (slash == arg ? NULL : arg, "1", &hints, &addrs))
{
noisy ("cannot resolve '%s': %s", arg, gai_strerror (e));
ok = false;
--
2.24.3 (Apple Git-128)
next reply other threads:[~2022-03-13 23:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-13 23:16 Iain Sandoe [this message]
2022-03-14 7:45 ` Richard Biener
2022-03-14 8:03 ` Iain Sandoe
2022-03-14 10:35 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220313231603.12480-1-iain@sandoe.co.uk \
--to=iains.gcc@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=iain@sandoe.co.uk \
--cc=jason@redhat.com \
--cc=nathan@acm.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).