D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 23340 - std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()
Summary: std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 major
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2022-09-17 15:14 UTC by Iain Buclaw
Modified: 2022-09-18 22:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Iain Buclaw 2022-09-17 15:14:16 UTC
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");
```
Comment 1 Dlang Bot 2022-09-18 16:47:05 UTC
@ibuclaw created dlang/phobos pull request #8572 "fix Issue 23340 - std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()" fixing this issue:

- fix Issue 23340 - std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()

https://github.com/dlang/phobos/pull/8572
Comment 2 Dlang Bot 2022-09-18 22:00:36 UTC
dlang/phobos pull request #8572 "fix Issue 23340 - std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()" was merged into master:

- 73411fa4e675de2542bda1f6a53f5f9647c99eb0 by Iain Buclaw:
  fix Issue 23340 - std.path: expandTilde erroneously raises onOutOfMemory on failed getpwam_r()

https://github.com/dlang/phobos/pull/8572