Procházet zdrojové kódy

[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>
tags/v1.20.1
Michael Brown před 8 roky
rodič
revize
fcf7751565
1 změnil soubory, kde provedl 7 přidání a 3 odebrání
  1. 7
    3
      src/arch/x86/interface/pcbios/int13.c

+ 7
- 3
src/arch/x86/interface/pcbios/int13.c Zobrazit soubor

@@ -561,6 +561,8 @@ static int int13_guess_geometry_hdd ( struct int13_drive *int13, void *scratch,
561 561
 	struct master_boot_record *mbr = scratch;
562 562
 	struct partition_table_entry *partition;
563 563
 	unsigned int i;
564
+	unsigned int end_head;
565
+	unsigned int end_sector;
564 566
 	int rc;
565 567
 
566 568
 	/* Default guess is xx/255/63 */
@@ -586,10 +588,12 @@ static int int13_guess_geometry_hdd ( struct int13_drive *int13, void *scratch,
586 588
 	 */
587 589
 	for ( i = 0 ; i < 4 ; i++ ) {
588 590
 		partition = &mbr->partitions[i];
589
-		if ( ! partition->type )
591
+		end_head = PART_HEAD ( partition->chs_end );
592
+		end_sector = PART_SECTOR ( partition->chs_end );
593
+		if ( ! ( partition->type && end_head && end_sector ) )
590 594
 			continue;
591
-		*heads = ( PART_HEAD ( partition->chs_end ) + 1 );
592
-		*sectors = PART_SECTOR ( partition->chs_end );
595
+		*heads = ( end_head + 1 );
596
+		*sectors = end_sector;
593 597
 		DBGC ( int13, "INT13 drive %02x guessing C/H/S xx/%d/%d based "
594 598
 		       "on partition %d\n",
595 599
 		       int13->drive, *heads, *sectors, ( i + 1 ) );

Načítá se…
Zrušit
Uložit