]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
disk: part_efi: range-check partition number
authorStephen Warren <swarren@nvidia.com>
Fri, 21 Sep 2012 09:50:58 +0000 (09:50 +0000)
committerTom Rini <trini@ti.com>
Tue, 25 Sep 2012 21:58:51 +0000 (14:58 -0700)
Enhance get_partition_info_efi() to range-check the partition number.
This prevents invalid partitions being accessed, and prevents access
beyond the end of the gpt_pte[] array.

Signed-off-by: Stephen Warren <swarren@nvidia.com>
disk/part_efi.c

index 02927a0d9da5a84e47817947b693eb7ff8e2c58a..2962fd8f67158889cf325fafb735484d50477a63 100644 (file)
@@ -173,6 +173,13 @@ int get_partition_info_efi(block_dev_desc_t * dev_desc, int part,
                return -1;
        }
 
+       if (part > le32_to_int(gpt_head->num_partition_entries) ||
+           !is_pte_valid(&gpt_pte[part - 1])) {
+               printf("%s: *** ERROR: Invalid partition number %d ***\n",
+                       __func__, part);
+               return -1;
+       }
+
        /* The ulong casting limits the maximum disk size to 2 TB */
        info->start = (ulong) le64_to_int(gpt_pte[part - 1].starting_lba);
        /* The ending LBA is inclusive, to calculate size, add 1 to it */