summaryrefslogtreecommitdiffstats
path: root/src/arch
diff options
context:
space:
mode:
authorMichael Brown2017-01-26 10:31:40 +0100
committerMichael Brown2017-01-26 10:31:40 +0100
commitfcf77515650272b9b51e18c115c66f48d33481b0 (patch)
treeca04739455aebc3c53cfc437b3b348bc46d8c5f5 /src/arch
parent[hyperv] Provide timer based on the 10MHz time reference count MSR (diff)
downloadipxe-fcf77515650272b9b51e18c115c66f48d33481b0.tar.gz
ipxe-fcf77515650272b9b51e18c115c66f48d33481b0.tar.xz
ipxe-fcf77515650272b9b51e18c115c66f48d33481b0.zip
[int13] Avoid potential division by zero
Avoid using a zero sector count to guess the disk geometry, since that would result in a division by zero when calculating the number of cylinders. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch')
-rw-r--r--src/arch/x86/interface/pcbios/int13.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/arch/x86/interface/pcbios/int13.c b/src/arch/x86/interface/pcbios/int13.c
index 6f16904d..8b2e134b 100644
--- a/src/arch/x86/interface/pcbios/int13.c
+++ b/src/arch/x86/interface/pcbios/int13.c
@@ -561,6 +561,8 @@ static int int13_guess_geometry_hdd ( struct int13_drive *int13, void *scratch,
struct master_boot_record *mbr = scratch;
struct partition_table_entry *partition;
unsigned int i;
+ unsigned int end_head;
+ unsigned int end_sector;
int rc;
/* Default guess is xx/255/63 */
@@ -586,10 +588,12 @@ static int int13_guess_geometry_hdd ( struct int13_drive *int13, void *scratch,
*/
for ( i = 0 ; i < 4 ; i++ ) {
partition = &mbr->partitions[i];
- if ( ! partition->type )
+ end_head = PART_HEAD ( partition->chs_end );
+ end_sector = PART_SECTOR ( partition->chs_end );
+ if ( ! ( partition->type && end_head && end_sector ) )
continue;
- *heads = ( PART_HEAD ( partition->chs_end ) + 1 );
- *sectors = PART_SECTOR ( partition->chs_end );
+ *heads = ( end_head + 1 );
+ *sectors = end_sector;
DBGC ( int13, "INT13 drive %02x guessing C/H/S xx/%d/%d based "
"on partition %d\n",
int13->drive, *heads, *sectors, ( i + 1 ) );