summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTopi Miettinen <toiwoton@gmail.com>2019-02-01 23:52:00 +0200
committerTopi Miettinen <toiwoton@gmail.com>2019-02-02 16:25:32 +0200
commita21760454db4b19e7299ead712fb895d8704b37d (patch)
tree2a24bf42e1983c4d81a17c29dca1e1477a2b4894 /src
parentcbed254f9673256836554b0b6e16941747f925f8 (diff)
downloadsystemd-a21760454db4b19e7299ead712fb895d8704b37d.tar.gz
Detect file truncation earlier in a few places
Users of read_one_line_file() for APIVFS entries are ignored as they are assumed to never get truncated.
Diffstat (limited to 'src')
-rw-r--r--src/basic/virt.c4
-rw-r--r--src/core/dynamic-user.c2
-rw-r--r--src/rfkill/rfkill.c4
3 files changed, 5 insertions, 5 deletions
diff --git a/src/basic/virt.c b/src/basic/virt.c
index 7766d9ca40..c7376bf5e4 100644
--- a/src/basic/virt.c
+++ b/src/basic/virt.c
@@ -469,11 +469,11 @@ int detect_container(void) {
/* Otherwise, PID 1 might have dropped this information into a file in /run. This is better than accessing
* /proc/1/environ, since we don't need CAP_SYS_PTRACE for that. */
r = read_one_line_file("/run/systemd/container", &m);
- if (r >= 0) {
+ if (r > 0) {
e = m;
goto translate_name;
}
- if (r != -ENOENT)
+ if (!IN_SET(r, -ENOENT, 0))
return log_debug_errno(r, "Failed to read /run/systemd/container: %m");
/* Fallback for cases where PID 1 was not systemd (for example, cases where init=/bin/sh is used. */
diff --git a/src/core/dynamic-user.c b/src/core/dynamic-user.c
index 530df70b80..7b00ee4bda 100644
--- a/src/core/dynamic-user.c
+++ b/src/core/dynamic-user.c
@@ -707,7 +707,7 @@ int dynamic_user_lookup_uid(Manager *m, uid_t uid, char **ret) {
xsprintf(lock_path, "/run/systemd/dynamic-uid/" UID_FMT, uid);
r = read_one_line_file(lock_path, &user);
- if (r == -ENOENT)
+ if (IN_SET(r, -ENOENT, 0))
return -ESRCH;
if (r < 0)
return r;
diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c
index ac21dc064c..8a92a4de6e 100644
--- a/src/rfkill/rfkill.c
+++ b/src/rfkill/rfkill.c
@@ -147,8 +147,8 @@ static int load_state(Context *c, const struct rfkill_event *event) {
return r;
r = read_one_line_file(state_file, &value);
- if (r == -ENOENT) {
- /* No state file? Then save the current state */
+ if (IN_SET(r, -ENOENT, 0)) {
+ /* No state file or it's truncated? Then save the current state */
r = write_string_file(state_file, one_zero(event->soft), WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC);
if (r < 0)