From: Mike Yuan Date: Thu, 14 Dec 2023 15:57:26 +0000 (+0800) Subject: machine: also clean up gid_map fscanf error handling X-Git-Tag: v256-rc1~1478^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F30482%2Fhead;p=thirdparty%2Fsystemd.git machine: also clean up gid_map fscanf error handling --- 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);