Message ID | 20220313231603.12480-1-iain@sandoe.co.uk |
---|---|
State | Committed |
Commit | 41f01c97153d403fb34eefac245bab8ba472beea |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D48D385842C for <patchwork@sourceware.org>; Sun, 13 Mar 2022 23:17:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D48D385842C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647213425; bh=Ah8qpFZuH3CcWC+NNFYpq9AvI5irbIvEOFkh9/1/85s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=i6DEm4Gi/CLzrjOGLPqJuUmIHYI2rzRczvxQoOl2jIM0TtBDMY7BbDSM4Pg8YQarD sCMc0q6hiOIZ7kVWG1Vx8PN3ZfxnmhpDeAOUFsiZflRJx1ob6zyugDlGPqTAxel/As Vzg5in0p2BWOaTjTEJb4NzMoJ/ERsxjAa8tktVfY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 5651E3858430 for <gcc-patches@gcc.gnu.org>; Sun, 13 Mar 2022 23:16:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5651E3858430 Received: by mail-wm1-x32e.google.com with SMTP id n31-20020a05600c3b9f00b003898fc06f1eso10923864wms.1 for <gcc-patches@gcc.gnu.org>; Sun, 13 Mar 2022 16:16:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :mime-version:content-transfer-encoding; bh=Ah8qpFZuH3CcWC+NNFYpq9AvI5irbIvEOFkh9/1/85s=; b=jCFD71HqZtryr4I1/P3p3bUeSXdIL/FkAD8p2pMmdSQQCqO487xLZaNBGk9yepBM+t /sgspDWFvwh+qIut4nBBfKJFurusr6dI89bp8fSJHtZWl4UKVmUGLTJU8Ae3dFjQAzTC veqLdB4aSEwnBOkdHtn3fF4W/JiXgC/bY/q8+l7j8UNn7/C5R92+TuEBFCVmoOE0wVIr 6OF9TxK8HHD14rFMdSpaqfzY8j3R3tblZ8dNqw8LXulKPvvkXpkqkboBoWTrBfa2FWCE l4p15nsMgM2aVm6xCm2L7L5XG5IOWDya4I3k0YDEFKDCnEIh8DXKrZ+4qBI0MEsVHvTc WBmQ== X-Gm-Message-State: AOAM530Rnp8+HGmJNC5IrMkw20h3mXlzYm8FZQ15ChHufLIRs8bx9RBe QWnls/ZGAKpwCA5aFtfu1FqWJFRmsgg= X-Google-Smtp-Source: ABdhPJy6XWXljQjrQsl+FkqgJK+IJRqBp3dnw64HI9GkPCRSfFOxrELVB0CPTTp6jtTigk15R8FIuQ== X-Received: by 2002:a7b:c759:0:b0:389:82c6:ac44 with SMTP id w25-20020a7bc759000000b0038982c6ac44mr22853509wmk.168.1647213370119; Sun, 13 Mar 2022 16:16:10 -0700 (PDT) Received: from localhost.localdomain (host81-138-1-83.in-addr.btopenworld.com. [81.138.1.83]) by smtp.gmail.com with ESMTPSA id r20-20020adfa154000000b001f0326a23e1sm12031290wrr.88.2022.03.13.16.16.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Mar 2022 16:16:09 -0700 (PDT) X-Google-Original-From: Iain Sandoe <iain@sandoe.co.uk> To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++tools: Work around a BSD bug in getaddrinfo(). Date: Sun, 13 Mar 2022 23:16:03 +0000 Message-Id: <20220313231603.12480-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Iain Sandoe via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe <iains.gcc@gmail.com>, nathan@acm.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[1/2] libcody: Do not use a dummy port number in getaddrinfo().
|
|
Commit Message
Iain Sandoe
March 13, 2022, 11:16 p.m. UTC
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(-)
Comments
On Mon, Mar 14, 2022 at 12:17 AM Iain Sandoe via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > 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? Why does the nullptr solution not work here? > 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) >
> On 14 Mar 2022, at 07:45, Richard Biener <richard.guenther@gmail.com> wrote: > > On Mon, Mar 14, 2022 at 12:17 AM Iain Sandoe via Gcc-patches > <gcc-patches@gcc.gnu.org> wrote: >> >> 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? > > 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 “/NN” (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 “hostname” parm is set to NULL, and we must supply a service-name/port number (for the “servname” parm), since getaddrinfo() does not permit both to be NULL. > >> 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) >>
On Mon, Mar 14, 2022 at 9:03 AM Iain Sandoe <iain@sandoe.co.uk> wrote: > > > > > On 14 Mar 2022, at 07:45, Richard Biener <richard.guenther@gmail.com> wrote: > > > > On Mon, Mar 14, 2022 at 12:17 AM Iain Sandoe via Gcc-patches > > <gcc-patches@gcc.gnu.org> wrote: > >> > >> 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? > > > > 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 “/NN” (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 “hostname” parm is set to NULL, and we must > supply a service-name/port number (for the “servname” parm), 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 <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) > >> >
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;