diff options
author | Bill Richardson <wfrichar@chromium.org> | 2010-10-12 07:33:15 -0700 |
---|---|---|
committer | Bill Richardson <wfrichar@chromium.org> | 2010-10-12 07:33:15 -0700 |
commit | c4e92af85ac2bfd90ab82c0b13bb0041595a0aff (patch) | |
tree | 5ff40795b6727f5aedd7a9f4101a76198ca29869 /cgpt/cmd_boot.c | |
parent | 2845b97df68da9387c400fb1eca5f6dbce1ddefa (diff) | |
download | vboot-c4e92af85ac2bfd90ab82c0b13bb0041595a0aff.tar.gz |
Address some security concerns in the cgpt tool.
1. Check for potential integer overflow in sector_bytes * sector_count.
2. Added O_NOFOLLOW to open() call - Is this enough?
3. Passing buffer length to GuidToStr(), PMBRToStr().
4. Use unsigned int in GetEntry() to determine stride.
5. Address conversion between UTF16 and UTF8.
Note: The UTF conversion is complex and troublesome, and needs careful
consideration to get right. For now, I've just forced the interpretation of
the partition name to 7-bit ASCII. That's sufficient for the needs of Chrome
OS, and I can file a new issue to handle UTF correctly.
BUG=chrome-os-partner:705
TEST=manual
Running "make runtests" invokes the tests/run_cgpt_tests.sh script, which checks the behavior and output of the cgpt tool.
Review URL: http://codereview.chromium.org/3594010
Change-Id: I5fd29796d8c929527e0cfbc6d5ccbcdc77502c6b
Diffstat (limited to 'cgpt/cmd_boot.c')
-rw-r--r-- | cgpt/cmd_boot.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/cgpt/cmd_boot.c b/cgpt/cmd_boot.c index 784684a2..56ab1d58 100644 --- a/cgpt/cmd_boot.c +++ b/cgpt/cmd_boot.c @@ -34,12 +34,12 @@ static void Usage(void) int cmd_boot(int argc, char *argv[]) { struct drive drive; - int partition = 0; + uint32_t partition = 0; char *bootfile = 0; int create_pmbr = 0; int retval = 1; int gpt_retval; - + int c; int errorcnt = 0; char *e = 0; @@ -63,7 +63,7 @@ int cmd_boot(int argc, char *argv[]) { case 'p': create_pmbr = 1; break; - + case 'h': Usage(); return CGPT_OK; @@ -98,7 +98,7 @@ int cmd_boot(int argc, char *argv[]) { Error("Unable to read PMBR\n"); goto done; } - + if (create_pmbr) { drive.pmbr.magic[0] = 0x1d; drive.pmbr.magic[1] = 0x9a; @@ -131,7 +131,7 @@ int cmd_boot(int argc, char *argv[]) { goto done; } - int index = partition - 1; + uint32_t index = partition - 1; GptEntry *entry = GetEntry(&drive.gpt, PRIMARY, index); memcpy(&drive.pmbr.boot_guid, &entry->unique, sizeof(Guid)); } @@ -152,9 +152,9 @@ int cmd_boot(int argc, char *argv[]) { close(fd); } - - char buf[256]; - GuidToStr(&drive.pmbr.boot_guid, buf); + + char buf[GUID_STRLEN]; + GuidToStr(&drive.pmbr.boot_guid, buf, sizeof(buf)); printf("%s\n", buf); // Write it all out |