From: Franck Bui Date: Tue, 20 Mar 2018 10:38:00 +0000 (+0100) Subject: sysusers: make sure to reset errno before calling fget*ent() X-Git-Tag: v239~523^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8499%2Fhead;p=thirdparty%2Fsystemd.git sysusers: make sure to reset errno before calling fget*ent() Due to the glibc interface we have to test errno in various places to detect if an error occured after calling fget*ent() helpers. --- diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index 0af4af06aad..43952e5f194 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -429,11 +429,12 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char return -EEXIST; } + errno = 0; + /* Make sure we keep the NIS entries (if any) at the end. */ if (IN_SET(pw->pw_name[0], '+', '-')) break; - errno = 0; if (putpwent(pw, passwd) < 0) return errno ? -errno : -EIO; @@ -471,6 +472,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char if (putpwent(&n, passwd) != 0) return errno ? -errno : -EIO; } + errno = 0; /* Append the remaining NIS entries if any */ while (pw) { @@ -478,6 +480,7 @@ static int write_temporary_passwd(const char *passwd_path, FILE **tmpfile, char if (putpwent(pw, passwd) < 0) return errno ? -errno : -EIO; + errno = 0; pw = fgetpwent(original); } if (!IN_SET(errno, 0, ENOENT)) @@ -637,6 +640,8 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** return -EEXIST; } + errno = 0; + /* Make sure we keep the NIS entries (if any) at the end. */ if (IN_SET(gr->gr_name[0], '+', '-')) break; @@ -672,6 +677,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** group_changed = true; } + errno = 0; /* Append the remaining NIS entries if any */ while (gr) { @@ -679,6 +685,7 @@ static int write_temporary_group(const char *group_path, FILE **tmpfile, char ** if (putgrent(gr, group) != 0) return errno > 0 ? -errno : -EIO; + errno = 0; gr = fgetgrent(original); } if (!IN_SET(errno, 0, ENOENT))