From f95fc91e4f0cd9837b109b9354a6b3fb8a42a0fc Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 1 Jan 2022 16:05:21 +0100 Subject: [PATCH] LibCore: Reset `errno` before using LibC pwd functions We should not expect LibC functions to clear `errno` on success, so if we want to use it for error checking after a call, we need to clear it before the call. --- Userland/Libraries/LibCore/System.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 462aa65236..92ab111dcd 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -404,6 +404,8 @@ ErrorOr chown(StringView pathname, uid_t uid, gid_t gid) ErrorOr> getpwnam(StringView name) { + errno = 0; + ::setpwent(); if (errno) return Error::from_syscall("getpwnam"sv, -errno); @@ -422,6 +424,8 @@ ErrorOr> getpwnam(StringView name) ErrorOr> getgrnam(StringView name) { + errno = 0; + ::setgrent(); if (errno) return Error::from_syscall("getgrnam"sv, -errno);