public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] libcody: Do not use a dummy port number in getaddrinfo().
@ 2022-03-13 23:15 Iain Sandoe
  2022-03-14  7:41 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Iain Sandoe @ 2022-03-13 23:15 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan

The getaddrinfo() call requires either a non-null name for the server or
a port service / number.  In the code that opens a connection we have
been calling this with a dummy port number of "0".  Unfortunately this
triggers a crashing bug in some BSD versions (and OSes importing that code).

In this part of the code we do not really need a port number, since it
is not reasonable to open a connection to an unspecified host.

Setting hints ai_flags field to 0, and the servname parm to nullptr works
around the BSD bug in this case.

Also posted upstream.

(fixes bad-mapper-2/3 on the versions affected).

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>

libcody/ChangeLog:

	* netclient.cc (OpenInet6): Do not provide a dummy port number
	in the getaddrinfo() call.
---
 libcody/netclient.cc | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/libcody/netclient.cc b/libcody/netclient.cc
index 7f81dd91810..558808be485 100644
--- a/libcody/netclient.cc
+++ b/libcody/netclient.cc
@@ -93,7 +93,7 @@ int OpenInet6 (char const **e, char const *name, int port)
     }
 
   addrinfo hints;
-  hints.ai_flags = AI_NUMERICSERV;
+  hints.ai_flags = 0;
   hints.ai_family = AF_INET6;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = 0;
@@ -102,9 +102,7 @@ int OpenInet6 (char const **e, char const *name, int port)
   hints.ai_canonname = nullptr;
   hints.ai_next = nullptr;
 
-  /* getaddrinfo requires a port number, but is quite happy to accept
-     invalid ones.  So don't rely on it.  */
-  if (int err = getaddrinfo (name, "0", &hints, &addrs))
+  if (int err = getaddrinfo (name, nullptr, &hints, &addrs))
     {
       errstr = gai_strerror (err);
       // What's the best errno to set?
-- 
2.24.3 (Apple Git-128)


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

* Re: [PATCH 1/2] libcody: Do not use a dummy port number in getaddrinfo().
  2022-03-13 23:15 [PATCH 1/2] libcody: Do not use a dummy port number in getaddrinfo() Iain Sandoe
@ 2022-03-14  7:41 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-03-14  7:41 UTC (permalink / raw)
  To: Iain Sandoe; +Cc: GCC Patches, Iain Sandoe, Nathan Sidwell

On Mon, Mar 14, 2022 at 12:16 AM Iain Sandoe via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> The getaddrinfo() call requires either a non-null name for the server or
> a port service / number.  In the code that opens a connection we have
> been calling this with a dummy port number of "0".  Unfortunately this
> triggers a crashing bug in some BSD versions (and OSes importing that code).
>
> In this part of the code we do not really need a port number, since it
> is not reasonable to open a connection to an unspecified host.
>
> Setting hints ai_flags field to 0, and the servname parm to nullptr works
> around the BSD bug in this case.
>
> Also posted upstream.
>
> (fixes bad-mapper-2/3 on the versions affected).
>
> tested on powerpc,i686-darwin9, x86-64-darwin10,17,20
> powerpc64le,powerpc64,x86_64-linux-gnu,
>
> OK for master?

LGTM.

> eventual backports?

After a while, yes.

> thanks
> Iain
>
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>
> libcody/ChangeLog:
>
>         * netclient.cc (OpenInet6): Do not provide a dummy port number
>         in the getaddrinfo() call.
> ---
>  libcody/netclient.cc | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/libcody/netclient.cc b/libcody/netclient.cc
> index 7f81dd91810..558808be485 100644
> --- a/libcody/netclient.cc
> +++ b/libcody/netclient.cc
> @@ -93,7 +93,7 @@ int OpenInet6 (char const **e, char const *name, int port)
>      }
>
>    addrinfo hints;
> -  hints.ai_flags = AI_NUMERICSERV;
> +  hints.ai_flags = 0;
>    hints.ai_family = AF_INET6;
>    hints.ai_socktype = SOCK_STREAM;
>    hints.ai_protocol = 0;
> @@ -102,9 +102,7 @@ int OpenInet6 (char const **e, char const *name, int port)
>    hints.ai_canonname = nullptr;
>    hints.ai_next = nullptr;
>
> -  /* getaddrinfo requires a port number, but is quite happy to accept
> -     invalid ones.  So don't rely on it.  */
> -  if (int err = getaddrinfo (name, "0", &hints, &addrs))
> +  if (int err = getaddrinfo (name, nullptr, &hints, &addrs))
>      {
>        errstr = gai_strerror (err);
>        // What's the best errno to set?
> --
> 2.24.3 (Apple Git-128)
>

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-13 23:15 [PATCH 1/2] libcody: Do not use a dummy port number in getaddrinfo() Iain Sandoe
2022-03-14  7:41 ` 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).