]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Detect file truncation earlier in a few places 11617/head
authorTopi Miettinen <toiwoton@gmail.com>
Fri, 1 Feb 2019 21:52:00 +0000 (23:52 +0200)
committerTopi Miettinen <toiwoton@gmail.com>
Sat, 2 Feb 2019 14:25:32 +0000 (16:25 +0200)
Users of read_one_line_file() for APIVFS entries are ignored as they are
assumed to never get truncated.

src/basic/virt.c
src/core/dynamic-user.c
src/rfkill/rfkill.c

index 7766d9ca40c42fa66e917d856ddd75cb14355356..c7376bf5e451201ee6c31aa6a4826b15fd8221e0 100644 (file)
@@ -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. */
index 530df70b800d6e86d6f380feb55d914f68d80184..7b00ee4bda0bd7bed5641807601310ed91e89ee8 100644 (file)
@@ -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;
index ac21dc064cae76bcf3de6518ed42094805c029e4..8a92a4de6ec5908e6fe5f2685d3e48b5505a2148 100644 (file)
@@ -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)