From 2b23c021f3137427a8b3f00e7702850be6e1c242 Mon Sep 17 00:00:00 2001 From: Louis Yung-Chieh Lo Date: Thu, 18 Nov 2010 09:53:10 +0800 Subject: Fixing the bug of CGPT when primary entry table is invalid. http://code.google.com/p/chromium-os/issues/detail?id=9279 This issue disclosed a bug of cgpt. The bug comes from the 'show' command always reads the primary entry table when '-i partition' is specified. I added an ANY_VALID constant for GetEntry to automatically select valid entry table. Also fixed the bugs in cmd_boot.c and cmd_find.c. In cmd_add.c, stop user to continue if any header/entry table is invalid. Also fixed the bug that untrusted header size could cause segmentation failure. Hungte, this is FYI. But welcome to do review. BUG=chromium-os:9279 TEST=RUNTESTS=1 emerge-x86-generic vboot_reference Manually tested: cgpt show /tmp/test -i 1 -b cgpt show /tmp/test cgpt add /tmp/test -i 1 -l TEST cgpt find /tmp/test -l STATE cgpt boot /tmp/test -i 1 Change-Id: Iaba9c635754096a82b3ec74634af184362d4e264 Change-Id: I6f3e87e3998457676e3388d2a6ed36c0564796d8 Review URL: http://codereview.chromium.org/5115002 --- cgpt/cmd_show.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cgpt/cmd_show.c') diff --git a/cgpt/cmd_show.c b/cgpt/cmd_show.c index a9963b5b..920a30fe 100644 --- a/cgpt/cmd_show.c +++ b/cgpt/cmd_show.c @@ -274,7 +274,7 @@ int cmd_show(int argc, char *argv[]) { } uint32_t index = partition - 1; - GptEntry *entry = GetEntry(&drive.gpt, PRIMARY, index); + GptEntry *entry = GetEntry(&drive.gpt, ANY_VALID, index); char buf[256]; // scratch buffer for string conversion if (single_item) { @@ -299,13 +299,13 @@ int cmd_show(int argc, char *argv[]) { printf("%s\n", buf); break; case 'S': - printf("%d\n", GetSuccessful(&drive.gpt, PRIMARY, index)); + printf("%d\n", GetSuccessful(&drive.gpt, ANY_VALID, index)); break; case 'T': - printf("%d\n", GetTries(&drive.gpt, PRIMARY, index)); + printf("%d\n", GetTries(&drive.gpt, ANY_VALID, index)); break; case 'P': - printf("%d\n", GetPriority(&drive.gpt, PRIMARY, index)); + printf("%d\n", GetPriority(&drive.gpt, ANY_VALID, index)); break; case 'A': printf("0x%x\n", entry->attrs.fields.gpt_att); @@ -322,7 +322,7 @@ int cmd_show(int argc, char *argv[]) { char type[GUID_STRLEN]; for (i = 0; i < GetNumberOfEntries(&drive.gpt); ++i) { - entry = GetEntry(&drive.gpt, PRIMARY, i); + entry = GetEntry(&drive.gpt, ANY_VALID, i); if (IsZero(&entry->type)) continue; -- cgit v1.2.1