public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain Buclaw <ibuclaw@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r10-11119] libphobos: Fix std.path.expandTilde raising onOutOfMemory
Date: Tue, 13 Dec 2022 23:05:31 +0000 (GMT)	[thread overview]
Message-ID: <20221213230531.E0257384C370@sourceware.org> (raw)

https://gcc.gnu.org/g:6ac6008ad52d44b3090967ca2f8d0b4e4d9bf549

commit r10-11119-g6ac6008ad52d44b3090967ca2f8d0b4e4d9bf549
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Tue Dec 13 23:54:22 2022 +0100

    libphobos: Fix std.path.expandTilde raising onOutOfMemory
    
    Fixes std.path.expandTilde erroneously raising onOutOfMemory after
    failed call to `getpwnam_r()'.
    
    libphobos/ChangeLog:
    
            * src/std/path.d (expandTilde): Handle more errno codes that could be
            left set by getpwnam_r.

Diff:
---
 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;

                 reply	other threads:[~2022-12-13 23:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221213230531.E0257384C370@sourceware.org \
    --to=ibuclaw@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).