The gpt command require the GPT backup header at the standard location
at the end of the device. Check the alternate LBA value before reading
the GPT backup header from the last usable LBA of the device.
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
/* Free pte before allocating again */
free(*gpt_pte);
+ /*
+ * Check that the alternate_lba entry points to the last LBA
+ */
+ if (le64_to_cpu(gpt_head->alternate_lba) != (dev_desc->lba - 1)) {
+ printf("%s: *** ERROR: Misplaced Backup GPT ***\n",
+ __func__);
+ return -1;
+ }
+
if (is_gpt_valid(dev_desc, (dev_desc->lba - 1),
gpt_head, gpt_pte) != 1) {
printf("%s: *** ERROR: Invalid Backup GPT ***\n",