From 5fa9fcefee51b0ea0dd27ab655a4acec6426a935 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Tue, 21 Apr 2009 12:05:46 -0700 Subject: [PATCH] hdt: Do not print information about buggy extended partitions 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 --- com32/hdt/hdt-cli-disk.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/com32/hdt/hdt-cli-disk.c b/com32/hdt/hdt-cli-disk.c index 8689a37..9bd4b1f 100644 --- a/com32/hdt/hdt-cli-disk.c +++ b/com32/hdt/hdt-cli-disk.c @@ -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); } /** -- 2.7.4