public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 2/2] c++tools: Work around a BSD bug in getaddrinfo().
@ 2022-03-13 23:16 Iain Sandoe
  2022-03-14  7:45 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Iain Sandoe @ 2022-03-13 23:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

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)


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-03-14 10:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-13 23:16 [PATCH 2/2] c++tools: Work around a BSD bug in getaddrinfo() Iain Sandoe
2022-03-14  7:45 ` Richard Biener
2022-03-14  8:03   ` Iain Sandoe
2022-03-14 10:35     ` Richard Biener

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).