From e18427642e7873852b4959597a4cd260da5bee0a Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Thu, 14 Dec 2023 23:57:26 +0800 Subject: [PATCH] machine: also clean up gid_map fscanf error handling --- src/machine/machine.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/machine/machine.c b/src/machine/machine.c index 1939843b643..af8a88f26ca 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -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); -- 2.47.3