summaryrefslogtreecommitdiff
path: root/cgpt/cmd_add.c
Commit message (Collapse)AuthorAgeFilesLines
* Refactor of cgpt tool for 32->64 autoupdate work.release-R18-1660.BJay Srinivasan2012-01-301-139/+31
| | | | | | | | | | | | | | | | | | This check-in splits the cgpt into two layers. The top layer (cmd_* files) does the command-line parsing and the bottom layer (cgpt_* files) does the actual cgpt work. This is done so that the bottom layer can be reused for the monolithic C++ post-installer code that will be done in subsequent checkins. BUG=chromium-os:25374 TEST=Tested with existing cgpt unit tests as well as running the cgpt commands manually. Change-Id: I69a31eb3e867a1430cac9a694581331368aa7bb4 Reviewed-on: https://gerrit.chromium.org/gerrit/14940 Reviewed-by: Jay Srinivasan <jaysri@chromium.org> Tested-by: Jay Srinivasan <jaysri@chromium.org> Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
* Fix for un-initialized code point variable.Louis Yung-Chieh Lo2010-11-221-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The original CL is http://codereview.chromium.org/5025003/, but it was reverted because the compiler complains code_point variable is not initialized. This CL just initializes it. This CL also adds few lines of code to make code more robust. Change-Id: Ib1329bcaeb4a1bd9abfe9e766b61bd0e52d2c260 BUG=chromium-os:7542 TEST=RUNTESTS=1 emerge-x86-generic vboot_reference Manually tested the following commands (intentionally mix Chinese and ASCII): export C=.../cgpt export D=/tmp/hda $C add $D -i 1 -l 批P踢T踢T許C夕C餐 $C find $D -l 批P踢T踢T許C夕C餐 $C show $D $C add $D -i 1 -l abc012 $C add $D -i 1 -l 是否看過坊間常見的許茹芸淚海慶功宴吃蓋飯第四集 $C add $D -i 1 -l 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ # ok and truncated $C add $D -i 1 -l `printf "\xf4\x91\x81\x81"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf4\x8f\xbf\xbf"` $C add $D -i 1 -l `printf "\xf4\x8f\x44\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf4\x8f\xbf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\xbf\xbf\xbf"` $C add $D -i 1 -l `printf "\xf0\xbf\xbf\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x84\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x90\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x88\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xed\x80\x80"` $C add $D -i 1 -l `printf "\xed\xa0\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\xbf\xbf"` $C add $D -i 1 -l `printf "\xe0\xbf\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\x90\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\xbf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xd0\x80"` $C add $D -i 1 -l `printf "\xd0\x11"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xd0"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xc0\xaf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\x80"` # (EXPECT: failed) Review URL: http://codereview.chromium.org/5104009
* Revert "The right implementation of CGPT label conversion between UTF8 and ↵Chris Sosa2010-11-191-5/+2
| | | | | | | | | | UTF16." This reverts commit 6965cbfed3352754f0ff9a270e3b330223b7154c. TBR=Change broke tree Change-Id: I5323799bf0bc2f9a1f2815f0c44fc90ca9a7bd77
* The right implementation of CGPT label conversion between UTF8 and UTF16.Louis Yung-Chieh Lo2010-11-191-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For security quick fix, the original UTF8/UTF16 conversion only supports ASCII area. This CL extends the library to support multiple code units conversion between UTF8 and UTF16. The UTF8/UTF16 encoded byte(s) would be decoded to code point first, then be encoded to UTF16/UTF8 correspondingly. Bill, please kindly review the UTF8/UTF16 conversion. Peter, please kindly comment if any security concern. Thanks. Change-Id: I99c558ff27556e0b8635ba2b8d9925d042e75cb2 BUG=chromium-os:7542 TEST=RUNTESTS=1 emerge-x86-generic vboot_reference Manually tested the following commands (intentionally mix Chinese and ASCII): export C=.../cgpt export D=/tmp/hda $C add $D -i 1 -l 批P踢T踢T許C夕C餐 $C find $D -l 批P踢T踢T許C夕C餐 $C show $D $C add $D -i 1 -l 批P踢T踢T許C夕C餐 $C find $D -l 批P踢T踢T許C夕C餐 $C add $D -i 1 -l abc012 $C add $D -i 1 -l 是否看過坊間常見的許茹芸淚海慶功宴吃蓋飯第四集 $C add $D -i 1 -l 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ # ok and truncated $C add $D -i 1 -l `printf "\xf4\x91\x81\x81"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf4\x8f\xbf\xbf"` $C add $D -i 1 -l `printf "\xf4\x8f\x44\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf4\x8f\xbf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\xbf\xbf\xbf"` $C add $D -i 1 -l `printf "\xf0\xbf\xbf\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x84\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x80\x90\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xf0\x88\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xed\x80\x80"` $C add $D -i 1 -l `printf "\xed\xa0\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\xbf\xbf"` $C add $D -i 1 -l `printf "\xe0\xbf\x44"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\x80\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\x90\x80"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xe0\xbf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xd0\x80"` $C add $D -i 1 -l `printf "\xd0\x11"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xd0"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\xc0\xaf"` # (EXPECT: failed) $C add $D -i 1 -l `printf "\x80"` # (EXPECT: failed) Review URL: http://codereview.chromium.org/5025003
* Fixing the bug of CGPT when primary entry table is invalid.Louis Yung-Chieh Lo2010-11-181-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Address some security concerns in the cgpt tool.Bill Richardson2010-10-121-7/+6
| | | | | | | | | | | | | | | | | | | | | | 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
* Reduce attributes size to comply with msc limitations.vbendeb2010-06-211-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | It turned out that shared verified boot library fails to work properly when compiled by msc in BIOS environment. The culprit was identified as failing 64 bit logical operations by preprocessor. It is probably possible to come up with a certain compile flag set to fix the operations, but it is not easy to modify and control the BIOS compilation environment. The alternative solution is to limit the size of the field in question to 16 bits (especially since this is the only part of the attributes field which is supposed to be altered by firmware. A union is being introduced in firmware/lib/cgptlib/include/gpt.h:GptEntry to allow accessing the field both as a 64 bit entity and a top 16 bit field. All places where this field is used are being modified appropriately. tests/Makefile is being fixed to allow controlling test run from the top level directory. Tested by building everything and running tests. All tests pass. Review URL: http://codereview.chromium.org/2799019
* Nearly complete rewrite of cgpt tool.Bill Richardson2010-06-111-0/+276
This fixes a number of bugs, adds a bunch of commands, and essentially makes cgpt ready to use as a replacement for gpt. Still to do is to add commands and options that will let it generated intentionally bad partitions, for use in testing. Review URL: http://codereview.chromium.org/2719008