Skip to content

Commit

Permalink
fstyp(8): fix exfat detection
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
cemeyer committed Jan 17, 2021
1 parent f3ea417 commit ddf6115
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions usr.sbin/fstyp/exfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,22 +330,23 @@ 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);

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);
Expand All @@ -357,20 +358,17 @@ 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
if (show_label)
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);
}

0 comments on commit ddf6115

Please sign in to comment.