Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 26 Jun 2018 06:18:59 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r335655 - head/sbin/fsck_msdosfs
Message-ID:  <201806260618.w5Q6Ix2j005816@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Tue Jun 26 06:18:59 2018
New Revision: 335655
URL: https://svnweb.freebsd.org/changeset/base/335655

Log:
  Fix division by zero when reading boot block by postponing division
  until it is necessary and after we validated bytes per sector is non-
  zero.
  
  Obtained from:	Android https://android-review.googlesource.com/c/platform/external/fsck_msdos/+/36362
  MFC after:	2 weeks

Modified:
  head/sbin/fsck_msdosfs/boot.c

Modified: head/sbin/fsck_msdosfs/boot.c
==============================================================================
--- head/sbin/fsck_msdosfs/boot.c	Tue Jun 26 04:06:49 2018	(r335654)
+++ head/sbin/fsck_msdosfs/boot.c	Tue Jun 26 06:18:59 2018	(r335655)
@@ -178,12 +178,8 @@ readboot(int dosfs, struct bootblock *boot)
 		/* Check backup bpbFSInfo?					XXX */
 	}
 
-	boot->ClusterOffset = (boot->bpbRootDirEnts * 32 +
-	    boot->bpbBytesPerSec - 1) / boot->bpbBytesPerSec +
-	    boot->bpbResSectors + boot->bpbFATs * boot->FATsecs -
-	    CLUST_FIRST * boot->bpbSecPerClust;
-
-	if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0) {
+	if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE_REAL != 0 ||
+	    boot->bpbBytesPerSec == 0) {
 		pfatal("Invalid sector size: %u", boot->bpbBytesPerSec);
 		return FSFATAL;
 	}
@@ -196,6 +192,10 @@ readboot(int dosfs, struct bootblock *boot)
 		boot->NumSectors = boot->bpbSectors;
 	} else
 		boot->NumSectors = boot->bpbHugeSectors;
+	boot->ClusterOffset = (boot->bpbRootDirEnts * 32 +
+	    boot->bpbBytesPerSec - 1) / boot->bpbBytesPerSec +
+	    boot->bpbResSectors + boot->bpbFATs * boot->FATsecs -
+	    CLUST_FIRST * boot->bpbSecPerClust;
 	boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) /
 	    boot->bpbSecPerClust;
 



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