From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=gdcproject.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gdcproject.org 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gdcproject.org; s=MBO0001; t=1670972758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Ou9bntPoFU/KaPXh1pIAWe0ySQh81f9JyY0FGKELHlI=; b=MvV6AiT27DR3PA2OetXzsxMmHpfjApA+7mL2iKcKy3weoaLWyLSSPbpEDLtzSwTPa7n6Dq Lk3WvaWg1pg5SArI6DKUbDi4n23EXKIp9dRnujq45NzBGOiJkYpheYiMFZLaUnaOqLBDmg +EgdE+nR8msf3xTNO0XWRNiteb/ZGy3pKxAWqrDx561uGBcrVJKExw2A47LmHz4yVAWqDj 4waykq4u6DwKc3uH1QTIiKQuyl/xo+1cjJoUNxSTbW49km5wnBuV7p3xaA57Xa+knRWtO4 VQ1VOnheEgM9UilIwSHKql1gmg6Tycue7PIYjftl3MtI7TcT7SHQOesDBM4JNQ== From: Iain Buclaw 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; -- 2.37.2