summaryrefslogtreecommitdiff
path: root/cgpt/cmd_add.c
diff options
context:
space:
mode:
authorLouis Yung-Chieh Lo <yjlou@chromium.org>2010-11-18 09:53:10 +0800
committerLouis Yung-Chieh Lo <yjlou@chromium.org>2010-11-18 09:53:10 +0800
commit2b23c021f3137427a8b3f00e7702850be6e1c242 (patch)
tree41236a552e70e816083eec3ed3c14718b01b57da /cgpt/cmd_add.c
parentfd337168bb4add01ccf9faa64a904052bd36b8ee (diff)
downloadvboot-2b23c021f3137427a8b3f00e7702850be6e1c242.tar.gz
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
Diffstat (limited to 'cgpt/cmd_add.c')
-rw-r--r--cgpt/cmd_add.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/cgpt/cmd_add.c b/cgpt/cmd_add.c
index 21085e71..dafcc50f 100644
--- a/cgpt/cmd_add.c
+++ b/cgpt/cmd_add.c
@@ -198,6 +198,13 @@ int cmd_add(int argc, char *argv[]) {
return CGPT_FAILED;
}
+ if (((drive.gpt.valid_headers & MASK_BOTH) != MASK_BOTH) ||
+ ((drive.gpt.valid_entries & MASK_BOTH) != MASK_BOTH)) {
+ Error("one of the GPT header/entries is invalid.\n"
+ "please run 'cgpt repair' before adding anything.\n");
+ return CGPT_FAILED;
+ }
+
uint32_t max_part = GetNumberOfEntries(&drive.gpt);
if (partition) {
if (partition > max_part) {