This adds a check for the return value when calling getpwuid_r.
There are situations where getpwuid_r returns non-zero on error, and also situations where it returns 0 but sets the result pointer to NULL. The former case was not being handled, but the latter case was. However if you're (un)lucky, getpwuid_r will return non-zero, but the pointer still happens to be null, in which case this issue won't be noticed.
This situation came up when running a statically linked binary inside a FROM scratch Docker container, where there's no /etc/passwd file.
This adds a check for the return value when calling getpwuid_r.
There are situations where
getpwuid_r
returns non-zero on error, and also situations where it returns 0 but sets theresult
pointer to NULL. The former case was not being handled, but the latter case was. However if you're (un)lucky,getpwuid_r
will return non-zero, but the pointer still happens to be null, in which case this issue won't be noticed.This situation came up when running a statically linked binary inside a
FROM scratch
Docker container, where there's no /etc/passwd file.Here's a repo that demonstrates the bug and the fix: https://github.com/adeschamps/whoami-bug