git: a072e2133ed3 - stable/12 - fstyp(8): fix exfat detection

Ed Maste emaste at FreeBSD.org
Tue Feb 2 21:14:03 UTC 2021


The branch stable/12 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=a072e2133ed36f1edf899068e6b026b129c919d8

commit a072e2133ed36f1edf899068e6b026b129c919d8
Author:     Conrad Meyer <cem at FreeBSD.org>
AuthorDate: 2021-01-17 19:55:06 +0000
Commit:     Ed Maste <emaste at FreeBSD.org>
CommitDate: 2021-02-02 21:12:31 +0000

    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)
    (cherry picked from commit ddf61156132b610915325769cbb93ea11be0d433)
---
 usr.sbin/fstyp/exfat.c | 18 ++++++++----------
 1 file 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);
 }


More information about the dev-commits-src-all mailing list