From patchwork Sun Mar 13 23:15:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 51926 Return-Path: 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 BD69F3858414 for ; Sun, 13 Mar 2022 23:16:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD69F3858414 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647213368; bh=MnG0tTsL3WiP6Hvd6uY4lXR/cSlQOMZyDG+xkN+6qOM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tvHSWd5hl58EZNjzpsqs4GTyWkYAGft6qVLztfyVucj0cyd4kDWD7efHsXV8hTidu JxR0Y25W3sxC7p1T7UqH/hGbuX5AQt+QZeYNnU1t/k3gILMyFBBA8/9aIILt5YnTXq sXyNqtXWN+ub6U7eYT/6L8ipYpn+E16a3pI33dNQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 393DA3858D28 for ; Sun, 13 Mar 2022 23:15:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 393DA3858D28 Received: by mail-wr1-x42d.google.com with SMTP id j26so21313176wrb.1 for ; Sun, 13 Mar 2022 16:15:40 -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=MnG0tTsL3WiP6Hvd6uY4lXR/cSlQOMZyDG+xkN+6qOM=; b=wFEYCqfRHzLNzacZIfvE5M9Fvk32wBVsUP7lwF0EQslw/njNVpq2/nTvWeKZmkaTRg fYzMVJK7icIocfK2coKuLdMhXxk66xn4uy/0c1Kx9XHdmc1BmHme4goE9Y3zKpPN8ly8 EAiTkFpNyGA5g3/wYNmaRfc/ImLpYYwxKw5tZbo8tw9Az09ogXKeurmgf+C1YokMANSk mChoxyMWyYJbccPcejA6ubhPbC0iv52KbNS8JJ8JxuCdBEa1K9juhKlQjCAXXJ2NwqC+ yIS7ZLyTMlpsyTvtbLl3UCRlSbfSTYXezRax/7kYYXhgUGjlDozTqUAbtjTYEsWF6jYc fj9g== X-Gm-Message-State: AOAM533fyV/i1d3Hol24/MhtOC7dsMJGtfkx6mkoI5IYyER6YbW6qEgT 5C7h1DPi5fRFgvlHKn7DX77vVwwYeMg= X-Google-Smtp-Source: ABdhPJzdsC3/QQaWcUKz21+FjoI65wOLOi7UDoNYUaa7KgbllLNDKXPQd9AkSm6+eWZugyRx9NAFMQ== X-Received: by 2002:adf:a35e:0:b0:1f0:9f2:a65e with SMTP id d30-20020adfa35e000000b001f009f2a65emr14849532wrb.535.1647213338865; Sun, 13 Mar 2022 16:15:38 -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 z6-20020adfd0c6000000b001f1ffd04672sm11278182wrh.12.2022.03.13.16.15.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Mar 2022 16:15:38 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH 1/2] libcody: Do not use a dummy port number in getaddrinfo(). Date: Sun, 13 Mar 2022 23:15:22 +0000 Message-Id: <20220313231522.12419-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.24.3 (Apple Git-128) MIME-Version: 1.0 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-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , nathan@acm.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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? From patchwork Sun Mar 13 23:16:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 51927 Return-Path: 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 ; 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 ; 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) X-Google-Original-From: Iain Sandoe 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 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-Patchwork-Original-From: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , nathan@acm.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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;