Fix division-by-zero when reading partition tables

When fsck_msdos was asked to analyze a device that contained
a partition table in its first sector fsck_msdos was doing a
division-by-zero because of mostly zeroed out fields. This
fix postpones the division until it is necessary, while
other tests already present detect the zeroed out fields and
so fsck_msdos fails in a controlled fashion.

Change-Id: Id2274b140449f4470f95a0215277f2f2de4cb7b0
Signed-off-by: Sebastian Rasmussen <sebastian.rasmussen@stericsson.com>
Signed-off-by: christian bejram <christian.bejram@stericsson.com>
diff --git a/boot.c b/boot.c
index 54d800f..6e797fd 100644
--- a/boot.c
+++ b/boot.c
@@ -193,12 +193,6 @@
 		/* 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 @@
 		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)