www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23340] New: std.path: expandTilde erroneously raises

https://issues.dlang.org/show_bug.cgi?id=23340

          Issue ID: 23340
           Summary: std.path: expandTilde erroneously raises onOutOfMemory
                    on failed getpwam_r()
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ibuclaw gdcproject.org

The condition for raising onOutOfMemory is:
```
if (errno != ERANGE &&
    // On BSD and OSX, errno can be left at 0 instead of set to ERANGE
    errno != 0)
    onOutOfMemoryError();
```


The documentation of getpwam_r says any of the following errno codes could be
set.
---
ERRORS
       0 or ENOENT or ESRCH or EBADF or EPERM or ...
              The given name or uid was not found.

       EINTR  A signal was caught; see signal(7).

       EIO    I/O error.

       EMFILE The per-process limit on the number of open file descriptors has
been reached.

       ENFILE The system-wide limit on the total number of open files has been
reached.

       ENOMEM Insufficient memory to allocate passwd structure.

       ERANGE Insufficient buffer space supplied.
---

The first set of errors should be checked, which breaks the loop before raising
an OOM Exception (ENOENT is not an OOM issue).

Test that triggers failure.
```
assert(expandTilde("~Idontexist/hey") == "~Idontexist/hey");
```

--
Sep 17 2022