summaryrefslogtreecommitdiffstats
path: root/c++tools
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2022-03-13 16:34:54 +0000
committerIain Sandoe <iain@sandoe.co.uk>2022-03-18 15:23:49 +0000
commit41f01c97153d403fb34eefac245bab8ba472beea (patch)
tree93602c1477fc8714346156be5a04ebc74496d78a /c++tools
parentlibcody: Do not use a dummy port number in getaddrinfo(). (diff)
downloadgcc-41f01c97153d403fb34eefac245bab8ba472beea.tar.gz
gcc-41f01c97153d403fb34eefac245bab8ba472beea.tar.bz2
gcc-41f01c97153d403fb34eefac245bab8ba472beea.tar.xz
c++tools: Work around a BSD bug in getaddrinfo().
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 no important, other than it should be in range. Work around the BSD bug by using "1" instead. Signed-off-by: Iain Sandoe <iain@sandoe.co.uk> c++tools/ChangeLog: * server.cc (accept_from): Use "1" as the dummy port number.
Diffstat (limited to 'c++tools')
-rw-r--r--c++tools/server.cc6
1 files changed, 5 insertions, 1 deletions
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)
360 hints.ai_next = NULL; 360 hints.ai_next = NULL;
361 361
362 struct addrinfo *addrs = NULL; 362 struct addrinfo *addrs = NULL;
363 if (int e = getaddrinfo (slash == arg ? NULL : arg, "0", &hints, &addrs)) 363 /* getaddrinfo requires either hostname or servname to be non-null, so that we must
364 set a port number (to cover the case that the string passed contains just /NN).
365 Use an arbitrary in-range port number, but avoiding "0" which triggers a bug on
366 some BSD variants. */
367 if (int e = getaddrinfo (slash == arg ? NULL : arg, "1", &hints, &addrs))
364 { 368 {
365 noisy ("cannot resolve '%s': %s", arg, gai_strerror (e)); 369 noisy ("cannot resolve '%s': %s", arg, gai_strerror (e));
366 ok = false; 370 ok = false;