Skip to content

Commit

Permalink
[int13] Avoid potential division by zero
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mcb30 committed Jan 26, 2017
1 parent f3ba0fb commit fcf7751
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/arch/x86/interface/pcbios/int13.c
Expand Up @@ -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 */
Expand All @@ -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 ) );
Expand Down

0 comments on commit fcf7751

Please sign in to comment.