diff options
| author | sin <sin@2f30.org> | 2013-11-14 11:24:08 +0000 |
|---|---|---|
| committer | sin <sin@2f30.org> | 2014-01-29 14:19:35 +0000 |
| commit | 6a5512835485ac501d983161ca15b311a95c5649 (patch) | |
| tree | c78b7e26ba7979b47e4793a453e1d0ab367f34a6 | |
| parent | ba3acfc0dcf1d0603bd9d6bdee1e319339b1a509 (diff) | |
Set errno to 0 before getpwuid() and check it afterwards
| -rw-r--r-- | slock.c | 5 |
1 files changed, 4 insertions, 1 deletions
| @@ -65,8 +65,11 @@ getpw(void) { /* only run as root */ | |||
| 65 | const char *rval; | 65 | const char *rval; |
| 66 | struct passwd *pw; | 66 | struct passwd *pw; |
| 67 | 67 | ||
| 68 | errno = 0; | ||
| 68 | pw = getpwuid(getuid()); | 69 | pw = getpwuid(getuid()); |
| 69 | if(!pw) | 70 | if (errno) |
| 71 | die("slock: getpwuid: %s\n", strerror(errno)); | ||
| 72 | else if (!pw) | ||
| 70 | die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); | 73 | die("slock: cannot retrieve password entry (make sure to suid or sgid slock)\n"); |
| 71 | endpwent(); | 74 | endpwent(); |
| 72 | rval = pw->pw_passwd; | 75 | rval = pw->pw_passwd; |
