[libc-commits] [libc] [libc] Read passwd records into a growable buffer (PR #224149)

via libc-commits libc-commits at lists.llvm.org
Thu Sep 17 00:20:08 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Jeff Bailey (kaladron)

<details>
<summary>Changes</summary>

Switch getpwent, getpwnam, and getpwuid to use DynamicBuffer so that passwd records of arbitrary length are supported without fixed size limits.

A single static DynamicBuffer and struct passwd are reused across getpwent, getpwnam, and getpwuid per POSIX, and endpwent closes the file stream without freeing the buffer so pointers returned prior to endpwent remain valid.

The reentrant lookups (getpwnam_r and getpwuid_r) remain non-allocating and return ERANGE when the caller's buffer is too small.

* Switch non-reentrant pwd lookups and iteration to DynamicBuffer
* Remove fixed 1024-byte buffer limit from pwd_utils
* Keep getpwnam_r and getpwuid_r non-allocating
* Update hermetic unit tests for long passwd records

Assisted-by: Automated tooling, human reviewed.

---
Full diff: https://github.com/llvm/llvm-project/pull/224149.diff


6 Files Affected:

- (modified) libc/src/pwd/CMakeLists.txt (+1) 
- (modified) libc/src/pwd/pwd_utils.cpp (+44-16) 
- (modified) libc/test/src/pwd/CMakeLists.txt (+8) 
- (modified) libc/test/src/pwd/getpwent_test.cpp (+88-19) 
- (modified) libc/test/src/pwd/getpwnam_test.cpp (+62-12) 
- (modified) libc/test/src/pwd/getpwuid_test.cpp (+21-12) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


https://github.com/llvm/llvm-project/pull/224149


More information about the libc-commits mailing list