hdt: Do not print information about buggy extended partitions
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Tue, 21 Apr 2009 19:05:46 +0000 (12:05 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Tue, 21 Apr 2009 19:05:46 +0000 (12:05 -0700)
Impact: bug fix

Add a sanity check before printing extended partitions.
As hpa notes in chain.c:

   Sanity check entry: must not extend outside the extended partition.
   This is necessary since some OSes put crap in some entries.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/hdt/hdt-cli-disk.c

index 8689a37..9bd4b1f 100644 (file)
@@ -109,6 +109,7 @@ static void process_ebr(struct driveinfo *drive_info, struct part_entry *ptab_ro
 {
        int error;
        char *error_buffer;
+       int offset;
 
        /* The ebr is located at the first sector of the extended partition */
        char* ebr = read_sectors(drive_info, ptab_root->start_lba, 1, &error);
@@ -121,7 +122,17 @@ static void process_ebr(struct driveinfo *drive_info, struct part_entry *ptab_ro
        }
 
        struct part_entry *ptab_child = (struct part_entry *)(ebr + PARTITION_TABLES_OFFSET);
-       return process_br(drive_info, ptab_child, ebr_seen, ptab_root);
+
+       if (!ptab_child->length)
+               return;
+
+       offset = ptab_child->start_lba + ptab_root->start_lba;
+
+       if ( offset + ptab_child->length <= ptab_root->start_lba ||
+            offset >= ptab_root->start_lba + ptab_root->length )
+               return;
+       else
+               return process_br(drive_info, ptab_child, ebr_seen, ptab_root);
 }
 
 /**