Author: delphij
Date: Tue Jul 10 02:46:31 2018
New Revision: 336158
URL: https://svnweb.freebsd.org/changeset/base/336158

Log:
  MFC r335655:
  
  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

Modified:
  stable/11/sbin/fsck_msdosfs/boot.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sbin/fsck_msdosfs/boot.c
==============================================================================
--- stable/11/sbin/fsck_msdosfs/boot.c  Tue Jul 10 02:43:22 2018        
(r336157)
+++ stable/11/sbin/fsck_msdosfs/boot.c  Tue Jul 10 02:46:31 2018        
(r336158)
@@ -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;
 
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to