sysusers: make sure to reset the returned value when EOF is reached in fget*ent_sane() wrappers (#8737)
To indicate that the there're no more entries, these wrappers return false but did leave the passed pointed unmodified. However EOF is not an error and is a very common case so initialize the output argument to NULL even in this case so callers don't need to do that. Fixes: #8721
This commit is contained in:
parent
613bddf7d1
commit
80359410c4
|
@ -775,14 +775,11 @@ int fgetpwent_sane(FILE *stream, struct passwd **pw) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
p = fgetpwent(stream);
|
p = fgetpwent(stream);
|
||||||
if (p == NULL) {
|
if (p == NULL && errno != ENOENT)
|
||||||
if (errno == ENOENT)
|
|
||||||
return false;
|
|
||||||
return errno > 0 ? -errno : -EIO;
|
return errno > 0 ? -errno : -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
*pw = p;
|
*pw = p;
|
||||||
return true;
|
return p != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fgetspent_sane(FILE *stream, struct spwd **sp) {
|
int fgetspent_sane(FILE *stream, struct spwd **sp) {
|
||||||
|
@ -793,14 +790,11 @@ int fgetspent_sane(FILE *stream, struct spwd **sp) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
s = fgetspent(stream);
|
s = fgetspent(stream);
|
||||||
if (s == NULL) {
|
if (s == NULL && errno != ENOENT)
|
||||||
if (errno == ENOENT)
|
|
||||||
return false;
|
|
||||||
return errno > 0 ? -errno : -EIO;
|
return errno > 0 ? -errno : -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
*sp = s;
|
*sp = s;
|
||||||
return true;
|
return s != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fgetgrent_sane(FILE *stream, struct group **gr) {
|
int fgetgrent_sane(FILE *stream, struct group **gr) {
|
||||||
|
@ -811,14 +805,11 @@ int fgetgrent_sane(FILE *stream, struct group **gr) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
g = fgetgrent(stream);
|
g = fgetgrent(stream);
|
||||||
if (g == NULL) {
|
if (g == NULL && errno != ENOENT)
|
||||||
if (errno == ENOENT)
|
|
||||||
return false;
|
|
||||||
return errno > 0 ? -errno : -EIO;
|
return errno > 0 ? -errno : -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
*gr = g;
|
*gr = g;
|
||||||
return true;
|
return g != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if ENABLE_GSHADOW
|
#if ENABLE_GSHADOW
|
||||||
|
@ -830,13 +821,10 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) {
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
s = fgetsgent(stream);
|
s = fgetsgent(stream);
|
||||||
if (s == NULL) {
|
if (s == NULL && errno != ENOENT)
|
||||||
if (errno == ENOENT)
|
|
||||||
return false;
|
|
||||||
return errno > 0 ? -errno : -EIO;
|
return errno > 0 ? -errno : -EIO;
|
||||||
}
|
|
||||||
|
|
||||||
*sg = s;
|
*sg = s;
|
||||||
return true;
|
return s != NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
2
test/TEST-21-SYSUSERS/test-12.expected-group
Normal file
2
test/TEST-21-SYSUSERS/test-12.expected-group
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
root:x:0:
|
||||||
|
systemd-coredump:x:1:
|
2
test/TEST-21-SYSUSERS/test-12.expected-passwd
Normal file
2
test/TEST-21-SYSUSERS/test-12.expected-passwd
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
root:x:0:0:root:/root:/bin/bash
|
||||||
|
systemd-coredump:x:1:1:systemd Core Dumper:/:/sbin/nologin
|
1
test/TEST-21-SYSUSERS/test-12.initial-group
Normal file
1
test/TEST-21-SYSUSERS/test-12.initial-group
Normal file
|
@ -0,0 +1 @@
|
||||||
|
root:x:0:
|
1
test/TEST-21-SYSUSERS/test-12.initial-passwd
Normal file
1
test/TEST-21-SYSUSERS/test-12.initial-passwd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
root:x:0:0:root:/root:/bin/bash
|
1
test/TEST-21-SYSUSERS/test-12.input
Normal file
1
test/TEST-21-SYSUSERS/test-12.input
Normal file
|
@ -0,0 +1 @@
|
||||||
|
u systemd-coredump 1 "systemd Core Dumper"
|
Loading…
Reference in a new issue