From patchwork Tue Dec 13 23:05:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 32977 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp411401wrn; Tue, 13 Dec 2022 15:07:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf6slXDv5Hd5PdFmsJLPzDOz4ucLSNPT3++V1qToMZnOQM1VnHKqcoPLMIh67/vaF21mVrAL X-Received: by 2002:a05:6402:5511:b0:45c:835c:c6d3 with SMTP id fi17-20020a056402551100b0045c835cc6d3mr16152017edb.4.1670972820570; Tue, 13 Dec 2022 15:07:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670972820; cv=none; d=google.com; s=arc-20160816; b=RmUkcjnyUUx+neNt0Qm8fyeYlMdZvwgeXIXSbT96qdxCwVNePLA2hNXf8bSTaOBdij D6+YesyFzmsyryeaf92ytVKULCU3mZPYEcySVZtqtAjEXM9jYMrd+xE2nWbQV/Ojag4I QP/jPUnJ61kwsNawwcryTYZE6uZZDQC5p0U/vHQZdpcATGlgT1Kp3PaJFVhjuoWmzwuR O5e7mzxb/I3JZEFfXUBBSO+Ti7/hZ2voMSCIRoEy4D5Bjgpxllg49yVzH6sst99ar+DM fgLEZ0P/6jhJI7izJKPQkM2+4bhBcpif55XiopWCGkxwgfwKwdupIW0/WgSF5K4onswY nDFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Ou9bntPoFU/KaPXh1pIAWe0ySQh81f9JyY0FGKELHlI=; b=UDUBmF5R/YdtxOoeh1LL7I4BUwMccQDbtM8RepCZ4uK4aGimasy3jJTa+JFS0wXgkC Vf8rd55U1NwXgRz9zK2PmPsavLcQx1nJmkPl4tA07Gh6S3FZzSIjIB9Zss8mv3QhF83I AkmDBcfEUEw21BrEn9i3b9yg3zq9AWqxmthjPSve7MfikNHz0gIT2mq1w3L6dkXFheza bKUvSj1lgRiL1QtFR/sLF7pU0dP8cExf1A0XQWliWlGU56myzZHTFjKhm8dJ13auue/E kiviFRZQuzSKr4p8yssUY/ZgOivrd3XOFGP6Q8Aogjta0F9+MOxbNri0r6leK+SFBEJJ lCwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yRhHyoa3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w16-20020a056402269000b0046fbd084e9dsi7300336edd.392.2022.12.13.15.07.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Dec 2022 15:07:00 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=yRhHyoa3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92770384C91E for ; Tue, 13 Dec 2022 23:06:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92770384C91E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670972819; bh=Ou9bntPoFU/KaPXh1pIAWe0ySQh81f9JyY0FGKELHlI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yRhHyoa3ii5YHg0EE1iHNMKCVPSnDBR+mRfcHxS1CTiLRgNOGpW4ZViWPPDpxQH6R 3/B9JB8clrIKM0F6ejk6qJhdmOcrbY6vsCHbouuylm9xtYvkPn62GAJkRipMXcMfXT yuKN0uW5CBSJ+jKZI2W6EGkBdOLnq20c9nteN+EE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [IPv6:2001:67c:2050:0:465::201]) by sourceware.org (Postfix) with ESMTPS id 67704384C377 for ; Tue, 13 Dec 2022 23:06:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 67704384C377 Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4NWvHV44TNz9sTY; Wed, 14 Dec 2022 00:05:58 +0100 (CET) To: gcc-patches@gcc.gnu.org Cc: Iain Buclaw Subject: [GCC-10][committed] libphobos: Fix std.path.expandTilde raising onOutOfMemory Date: Wed, 14 Dec 2022 00:05:52 +0100 Message-Id: <20221213230552.874531-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4NWvHV44TNz9sTY X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752141996248040814?= X-GMAIL-MSGID: =?utf-8?q?1752141996248040814?= Hi, This patch backports from mainline a fix for std.path.expandTilde erroneously raising onOutOfMemory after failed call to `getpwnam_r()'. Regression tested on x86_64-linux-gnu/-m32/-mx32, committed to releases/gcc-10 branch. Regards, Iain. --- libphobos/ChangeLog: * src/std/path.d (expandTilde): Handle more errno codes that could be left set by getpwnam_r. --- libphobos/src/std/path.d | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/libphobos/src/std/path.d b/libphobos/src/std/path.d index 4a435efba6c..d250953ee1c 100644 --- a/libphobos/src/std/path.d +++ b/libphobos/src/std/path.d @@ -3850,7 +3850,7 @@ string expandTilde(string inputPath) nothrow version (Posix) { import core.exception : onOutOfMemoryError; - import core.stdc.errno : errno, ERANGE; + import core.stdc.errno : errno, EBADF, ENOENT, EPERM, ERANGE, ESRCH; import core.stdc.stdlib : malloc, free, realloc; /* Joins a path from a C string to the remainder of path. @@ -3950,7 +3950,7 @@ string expandTilde(string inputPath) nothrow scope(exit) free(extra_memory); passwd result; - while (1) + loop: while (1) { extra_memory = cast(char*) realloc(extra_memory, extra_memory_size * char.sizeof); if (extra_memory == null) @@ -3969,10 +3969,23 @@ string expandTilde(string inputPath) nothrow break; } - if (errno != ERANGE && + switch (errno) + { + case ERANGE: // On BSD and OSX, errno can be left at 0 instead of set to ERANGE - errno != 0) - onOutOfMemoryError(); + case 0: + break; + + case ENOENT: + case ESRCH: + case EBADF: + case EPERM: + // The given name or uid was not found. + break loop; + + default: + onOutOfMemoryError(); + } // extra_memory isn't large enough import core.checkedint : mulu;