From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by sourceware.org (Postfix) with ESMTPS id 960CB385E00D for ; Mon, 14 Mar 2022 10:35:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 960CB385E00D Received: by mail-ed1-x52b.google.com with SMTP id y22so19168698eds.2 for ; Mon, 14 Mar 2022 03:35:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=1l2VekvTdjhKtVFlMu/P1Lgh/bu4mlPH90cCqpHD9nU=; b=Nryc6wEm8VcLVeX5U21sBr7oIEvBJnmkPzlALkJzhuKpdd8h83qlpdX/CqB1wlp+Ma uB729RqPF3SownFyklv+ZB1zwBp0DfTi21Yhgqn4VD88K62OERE/TpHd3rKx1ujuy3Ad u82xqDAhsBlieoE+rVP5qhZFCEJGFqYJEfYF++2i+5kw30jwcOGkLfpJ57DmCXFUPDLo dSwKoAQtpDAXYntYZsEWkqPPWL+vnTIJthy7DyR/VZG3W4QzbJnl89vgXRfi4pMDf6l8 RmdlRloShyj7zE7BF20sxG0kB0wwCzvNkjrCx37D3zRF9Y2i+kFkRi1O61t0sZdJS7x0 KJVA== X-Gm-Message-State: AOAM532s1Avhv0NGQ2V4osYgDvQzD9MSL7BS43r6/EH5hPhuoswF6OkZ bGx7aEOOXP3pa1wk/RdwNvUm4YmEwn+h1HtlcNU= X-Google-Smtp-Source: ABdhPJwiD1p2AGIw/hBBqE5gfYdfDgW6Bu34e7A3slnuJjr3I5JN7z8ZQjg2u8yxnzaPUqLtsCRgYblEwbE1L1Zm66U= X-Received: by 2002:a05:6402:2682:b0:416:cee9:53db with SMTP id w2-20020a056402268200b00416cee953dbmr14627268edd.194.1647254117135; Mon, 14 Mar 2022 03:35:17 -0700 (PDT) MIME-Version: 1.0 References: <20220313231603.12480-1-iain@sandoe.co.uk> <9E994D3A-514A-42D4-8137-16903B81E1BB@sandoe.co.uk> In-Reply-To: <9E994D3A-514A-42D4-8137-16903B81E1BB@sandoe.co.uk> From: Richard Biener Date: Mon, 14 Mar 2022 11:35:06 +0100 Message-ID: Subject: Re: [PATCH 2/2] c++tools: Work around a BSD bug in getaddrinfo(). To: Iain Sandoe Cc: GCC Patches , Nathan Sidwell Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2022 10:35:20 -0000 On Mon, Mar 14, 2022 at 9:03 AM Iain Sandoe wrote: > > > > > On 14 Mar 2022, at 07:45, Richard Biener w= rote: > > > > On Mon, Mar 14, 2022 at 12:17 AM Iain Sandoe via Gcc-patches > > wrote: > >> > >> Some versions of the BSD getaddrinfo() call do not work with the speci= fic > >> input of "0" for the servname entry (a segv results). Since we are ma= king > >> 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" inst= ead. > >> > >> tested on powerpc,i686-darwin9, x86-64-darwin10,17,20 > >> powerpc64le,powerpc64,x86_64-linux-gnu, > >> > >> OK for master? > >> eventual backports? > > > > Why does the nullptr solution not work here? > > Because this code is setting a netmask and, if I read it correctly (we do= not seem to have > a test for it), it can be called with =E2=80=9C/NN=E2=80=9D (where NN is = the number of bits and there is no host > name before the slash). > > So in this case, in the getaddrinfo() call, the =E2=80=9Chostname=E2=80= =9D parm is set to NULL, and we must > supply a service-name/port number (for the =E2=80=9Cservname=E2=80=9D par= m), since getaddrinfo() does not > permit both to be NULL. I see. I guess the fix is OK then. Richard. > > > > >> thanks > >> Iain > >> > >> Signed-off-by: Iain Sandoe > >> > >> 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 =3D NULL; > >> > >> struct addrinfo *addrs =3D NULL; > >> - if (int e =3D getaddrinfo (slash =3D=3D arg ? NULL : arg, "0", &hin= ts, &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 cont= ains just /NN). > >> + Use an arbitrary in-range port number, but avoiding "0" which tr= iggers a bug on > >> + some BSD variants. */ > >> + if (int e =3D getaddrinfo (slash =3D=3D arg ? NULL : arg, "1", &hin= ts, &addrs)) > >> { > >> noisy ("cannot resolve '%s': %s", arg, gai_strerror (e)); > >> ok =3D false; > >> -- > >> 2.24.3 (Apple Git-128) > >> >