]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
machine: also clean up gid_map fscanf error handling 30482/head
authorMike Yuan <me@yhndnzj.com>
Thu, 14 Dec 2023 15:57:26 +0000 (23:57 +0800)
committerMike Yuan <me@yhndnzj.com>
Sat, 16 Dec 2023 10:49:20 +0000 (18:49 +0800)
src/machine/machine.c

index 1939843b643bd2e1ac5c824fa30966a9034c5521..af8a88f26caea134fd3a8f922092deeda7e7fb71 100644 (file)
@@ -659,7 +659,7 @@ int machine_get_uid_shift(Machine *m, uid_t *ret) {
         uid_t uid_base, uid_shift, uid_range;
         gid_t gid_base, gid_shift, gid_range;
         _cleanup_fclose_ FILE *f = NULL;
-        int k, r;
+        int r;
 
         assert(m);
         assert(ret);
@@ -718,13 +718,12 @@ int machine_get_uid_shift(Machine *m, uid_t *ret) {
 
         /* Read the first line. There's at least one. */
         errno = 0;
-        k = fscanf(f, GID_FMT " " GID_FMT " " GID_FMT "\n", &gid_base, &gid_shift, &gid_range);
-        if (k != 3) {
-                if (ferror(f))
-                        return errno_or_else(EIO);
-
+        r = fscanf(f, GID_FMT " " GID_FMT " " GID_FMT "\n", &gid_base, &gid_shift, &gid_range);
+        if (r == EOF)
+                return errno_or_else(ENOMSG);
+        assert(r >= 0);
+        if (r != 3)
                 return -EBADMSG;
-        }
 
         /* If there's more than one line, then we don't support this file. */
         r = safe_fgetc(f, NULL);