machine: also clean up gid_map fscanf error handling

This commit is contained in:
Mike Yuan
2023-12-14 23:57:26 +08:00
parent 7312c422f0
commit e18427642e

View 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);