소스 검색

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.
Andreas Kling 3 년 전
부모
커밋
f95fc91e4f
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      Userland/Libraries/LibCore/System.cpp

+ 4 - 0
Userland/Libraries/LibCore/System.cpp

@@ -404,6 +404,8 @@ ErrorOr<void> chown(StringView pathname, uid_t uid, gid_t gid)
 
 ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
 {
+    errno = 0;
+
     ::setpwent();
     if (errno)
         return Error::from_syscall("getpwnam"sv, -errno);
@@ -422,6 +424,8 @@ ErrorOr<Optional<struct passwd>> getpwnam(StringView name)
 
 ErrorOr<Optional<struct group>> getgrnam(StringView name)
 {
+    errno = 0;
+
     ::setgrent();
     if (errno)
         return Error::from_syscall("getgrnam"sv, -errno);