Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Jan 2021 19:57:57 GMT
From:      Conrad Meyer <cem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: ddf61156132b - main - fstyp(8): fix exfat detection
Message-ID:  <202101171957.10HJvvmT094552@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by cem:

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

commit ddf61156132b610915325769cbb93ea11be0d433
Author:     Conrad Meyer <cem@FreeBSD.org>
AuthorDate: 2021-01-17 19:55:06 +0000
Commit:     Conrad Meyer <cem@FreeBSD.org>
CommitDate: 2021-01-17 19:55:06 +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)
---
 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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101171957.10HJvvmT094552>