summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Baptiste Queru <jbq@google.com>2012-05-29 08:45:33 -0700
committerandroid code review <noreply-gerritcodereview@google.com>2012-05-29 08:45:34 -0700
commitf717a6ed5b25287fa9417096f90e7c047ace0c15 (patch)
tree5a6efa49bc9563936d9eb661b427a9769658e24f
parente1dd6c88cff4f71c298921ef34f7662eb227aacf (diff)
parentfe7400ddb5e99a790cd3977f9e5151d8ea929a14 (diff)
downloadandroid_external_fsck_msdos-f717a6ed5b25287fa9417096f90e7c047ace0c15.tar.gz
android_external_fsck_msdos-f717a6ed5b25287fa9417096f90e7c047ace0c15.tar.bz2
android_external_fsck_msdos-f717a6ed5b25287fa9417096f90e7c047ace0c15.zip
Merge "Fix division-by-zero when reading partition tables"
-rw-r--r--boot.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/boot.c b/boot.c
index 54d800f..6e797fd 100644
--- a/boot.c
+++ b/boot.c
@@ -193,12 +193,6 @@ readboot(dosfs, boot)
/* Check backup FSInfo? XXX */
}
- boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
- / boot->BytesPerSec
- + boot->ResSectors
- + boot->FATs * boot->FATsecs
- - CLUST_FIRST * boot->SecPerClust;
-
if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
pfatal("Invalid sector size: %u", boot->BytesPerSec);
return FSFATAL;
@@ -207,11 +201,22 @@ readboot(dosfs, boot)
pfatal("Invalid cluster size: %u", boot->SecPerClust);
return FSFATAL;
}
+ if (boot->BytesPerSec == 0) {
+ pfatal("Invalid sector size: %u", boot->BytesPerSec);
+ return FSFATAL;
+ }
if (boot->Sectors) {
boot->HugeSectors = 0;
boot->NumSectors = boot->Sectors;
} else
boot->NumSectors = boot->HugeSectors;
+
+ boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1)
+ / boot->BytesPerSec
+ + boot->ResSectors
+ + boot->FATs * boot->FATsecs
+ - CLUST_FIRST * boot->SecPerClust;
+
boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->SecPerClust;
if (boot->flags&FAT32)