diff options
author | Conrad Meyer <cem@FreeBSD.org> | 2021-01-17 19:55:06 +0000 |
---|---|---|
committer | Conrad Meyer <cem@FreeBSD.org> | 2021-01-17 19:55:06 +0000 |
commit | ddf61156132b610915325769cbb93ea11be0d433 (patch) | |
tree | fa45308afbed8b155c25c9ad537c9c5bfbcec21f | |
parent | f3ea417f96b011a7eb4f43e3142e572833287ef4 (diff) | |
download | src-ddf61156132b610915325769cbb93ea11be0d433.tar.gz src-ddf61156132b610915325769cbb93ea11be0d433.zip |
fstyp(8): fix exfat detection
In the presence of high-level errors (spec violations, bad boot blocks
checksum), report non-detection instead of detection.
PR: 252787 (related, but does not fully address)
-rw-r--r-- | usr.sbin/fstyp/exfat.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/usr.sbin/fstyp/exfat.c b/usr.sbin/fstyp/exfat.c index d77ba9253d39..3f10cb6a9e5a 100644 --- a/usr.sbin/fstyp/exfat.c +++ b/usr.sbin/fstyp/exfat.c @@ -330,14 +330,15 @@ fstyp_exfat(FILE *fp, char *label, size_t size) uint32_t chksum; int error; + error = 1; cksect = NULL; ev = (struct exfat_vbr *)read_buf(fp, 0, 512); if (ev == NULL || strncmp(ev->ev_fsname, "EXFAT ", 8) != 0) - goto fail; + goto out; if (ev->ev_log_bytes_per_sect < 9 || ev->ev_log_bytes_per_sect > 12) { warnx("exfat: Invalid BytesPerSectorShift"); - goto done; + goto out; } bytespersec = (1u << ev->ev_log_bytes_per_sect); @@ -345,7 +346,7 @@ fstyp_exfat(FILE *fp, char *label, size_t size) error = exfat_compute_boot_chksum(fp, MAIN_BOOT_REGION_SECT, bytespersec, &chksum); if (error != 0) - goto done; + goto out; cksect = read_sect(fp, MAIN_BOOT_REGION_SECT + SUBREGION_CHKSUM_SECT, bytespersec); @@ -357,7 +358,8 @@ fstyp_exfat(FILE *fp, char *label, size_t size) if (chksum != le32toh(cksect[0])) { warnx("exfat: Found checksum 0x%08x != computed 0x%08x", le32toh(cksect[0]), chksum); - goto done; + error = 1; + goto out; } #ifdef WITH_ICONV @@ -365,12 +367,8 @@ fstyp_exfat(FILE *fp, char *label, size_t size) exfat_find_label(fp, ev, bytespersec, label, size); #endif -done: +out: free(cksect); free(ev); - return (0); - -fail: - free(ev); - return (1); + return (error != 0); } |