From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 ; 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 ; 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) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.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) Reply-To: iain@sandoe.co.uk 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Mar 2022 23:16:12 -0000 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 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)