aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranck Bui <fbui@suse.com>2018-04-18 18:32:21 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-04-18 18:32:21 +0200
commit80359410c4056ffa9113837cebac8bdfde3f3ac2 (patch)
treea6b09971e307c1bb9b8bbc4b2b4507b7c9041d08
parentMerge pull request #8709 from poettering/format-table (diff)
downloadsystemd-80359410c4056ffa9113837cebac8bdfde3f3ac2.tar.gz
systemd-80359410c4056ffa9113837cebac8bdfde3f3ac2.tar.bz2
systemd-80359410c4056ffa9113837cebac8bdfde3f3ac2.zip
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
-rw-r--r--src/basic/user-util.c28
-rw-r--r--test/TEST-21-SYSUSERS/test-12.expected-group2
-rw-r--r--test/TEST-21-SYSUSERS/test-12.expected-passwd2
-rw-r--r--test/TEST-21-SYSUSERS/test-12.initial-group1
-rw-r--r--test/TEST-21-SYSUSERS/test-12.initial-passwd1
-rw-r--r--test/TEST-21-SYSUSERS/test-12.input1
6 files changed, 15 insertions, 20 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index 1effd55b0..0f0f21dbc 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -775,14 +775,11 @@ int fgetpwent_sane(FILE *stream, struct passwd **pw) {
errno = 0;
p = fgetpwent(stream);
- if (p == NULL) {
- if (errno == ENOENT)
- return false;
+ if (p == NULL && errno != ENOENT)
return errno > 0 ? -errno : -EIO;
- }
*pw = p;
- return true;
+ return p != NULL;
}
int fgetspent_sane(FILE *stream, struct spwd **sp) {
@@ -793,14 +790,11 @@ int fgetspent_sane(FILE *stream, struct spwd **sp) {
errno = 0;
s = fgetspent(stream);
- if (s == NULL) {
- if (errno == ENOENT)
- return false;
+ if (s == NULL && errno != ENOENT)
return errno > 0 ? -errno : -EIO;
- }
*sp = s;
- return true;
+ return s != NULL;
}
int fgetgrent_sane(FILE *stream, struct group **gr) {
@@ -811,14 +805,11 @@ int fgetgrent_sane(FILE *stream, struct group **gr) {
errno = 0;
g = fgetgrent(stream);
- if (g == NULL) {
- if (errno == ENOENT)
- return false;
+ if (g == NULL && errno != ENOENT)
return errno > 0 ? -errno : -EIO;
- }
*gr = g;
- return true;
+ return g != NULL;
}
#if ENABLE_GSHADOW
@@ -830,13 +821,10 @@ int fgetsgent_sane(FILE *stream, struct sgrp **sg) {
errno = 0;
s = fgetsgent(stream);
- if (s == NULL) {
- if (errno == ENOENT)
- return false;
+ if (s == NULL && errno != ENOENT)
return errno > 0 ? -errno : -EIO;
- }
*sg = s;
- return true;
+ return s != NULL;
}
#endif
diff --git a/test/TEST-21-SYSUSERS/test-12.expected-group b/test/TEST-21-SYSUSERS/test-12.expected-group
new file mode 100644
index 000000000..5d94846ed
--- /dev/null
+++ b/test/TEST-21-SYSUSERS/test-12.expected-group
@@ -0,0 +1,2 @@
+root:x:0:
+systemd-coredump:x:1:
diff --git a/test/TEST-21-SYSUSERS/test-12.expected-passwd b/test/TEST-21-SYSUSERS/test-12.expected-passwd
new file mode 100644
index 000000000..75fe9b420
--- /dev/null
+++ b/test/TEST-21-SYSUSERS/test-12.expected-passwd
@@ -0,0 +1,2 @@
+root:x:0:0:root:/root:/bin/bash
+systemd-coredump:x:1:1:systemd Core Dumper:/:/sbin/nologin
diff --git a/test/TEST-21-SYSUSERS/test-12.initial-group b/test/TEST-21-SYSUSERS/test-12.initial-group
new file mode 100644
index 000000000..1dbf9013e
--- /dev/null
+++ b/test/TEST-21-SYSUSERS/test-12.initial-group
@@ -0,0 +1 @@
+root:x:0:
diff --git a/test/TEST-21-SYSUSERS/test-12.initial-passwd b/test/TEST-21-SYSUSERS/test-12.initial-passwd
new file mode 100644
index 000000000..aebc4923f
--- /dev/null
+++ b/test/TEST-21-SYSUSERS/test-12.initial-passwd
@@ -0,0 +1 @@
+root:x:0:0:root:/root:/bin/bash
diff --git a/test/TEST-21-SYSUSERS/test-12.input b/test/TEST-21-SYSUSERS/test-12.input
new file mode 100644
index 000000000..291312027
--- /dev/null
+++ b/test/TEST-21-SYSUSERS/test-12.input
@@ -0,0 +1 @@
+u systemd-coredump 1 "systemd Core Dumper"