Repository navigation
fsutils/mkgpt: fix exit status, GPT geometry, GUID and input validation - #4289
Open
JianyuWang0623 wants to merge 8 commits into
Open
JianyuWang0623 wants to merge 8 commits into
JianyuWang0623 wants to merge 8 commits into
Conversation
The write path returned -1 even after both tables were written, so the command always exited with 255. Set ret to 0 on the success path. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
The header counted the backup entry area as usable (sz-33) and a fill entry stopped one LBA short of the end. Use sz-34 and end :0 fills at the last usable LBA. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
=linux selected the Microsoft Basic Data type instead of the Linux filesystem data type 0FC63DAF-8483-4772-8E79-3D69D8477DE4. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
The upper bound compared with >, so a full table still wrote entry[128] past the end of the array. Use >= so at most 128 entries are accepted. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
A failed flush was reported as success, so callers could proceed while the tables are not durable. Propagate the fsync() error instead. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
Long names were silently truncated and duplicates were accepted, so two entries could share one GPT name. Reject both in add_ptn(), which every parser path goes through. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
parse_size() ignored the strtoull end pointer and could overflow the unit multiply, so trailing garbage was accepted and huge values wrapped. Require full token consumption and reject overflow. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
When the disk cannot hold both GPT copies there is no usable area and the size math underflows; reject disks smaller than 68 sectors. Co-authored-by: multica-agent <github@multica.ai> Assisted-by: OpenCode:mimo-v2.6-pro Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
JianyuWang0623
marked this pull request as ready for review
December 4, 2026 03:36
xiaoxiang781216
approved these changes
Dec 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This series fixes eight bugs in
fsutils/mkgpt: a successful write alwaysexited 255, the last usable LBA overlapped the backup entry array,
=linuxselected the Microsoft Basic Data GUID instead of the Linux filesystem data
one, a full partition table wrote one entry past the 128-entry array, a
failed
fsync()was reported as success, over-long and duplicate partitionnames were silently accepted, size suffix parsing accepted trailing garbage
and could wrap, and disks too small for both GPT copies underflowed the size
math.
Impact
mkgpt writeexits 0 on success (previouslyalways 255) and fails when
fsync()errors (previously reported success).:0fillpartitions end at it (previously sz-33, overlapping the backup entry
array), and
=linuxwrites the Linux filesystem data GUID0FC63DAF-8483-4772-8E79-3D69D8477DE4 (previously the Microsoft Basic Data
GUID EBD0A0A2-B9E5-4433-87C0-68B6B72699C7).
names, malformed or overflowing size suffixes, a 129th partition entry and
disks smaller than 68 sectors are now rejected with an error instead of
silently writing a corrupt table.
Testing
Build Host: Ubuntu 22.04 x86_64, gcc (Ubuntu 13.4.0-6ubuntu1
22ppa2) 13.4.0;Target:
sim:nsh(x86_64) withCONFIG_FSUTILS_MKGPT=yandCONFIG_FS_TMPFS=y, run natively on the build host. Commands were fed onthe sim console (
./nuttxreading the session from stdin).Write and read back a 256 KiB (512 sector) image with a
:0fill partition,then check the exit status (before:
mkgpt writereturned 255 even onsuccess):
The fill partition ends at LBA 478 = 512 - 34, the last usable LBA before
the 32 backup entry LBAs and the backup header. The
cpartition entrytype GUID (bytes at offset 1280 of the image, little-endian mixed encoding):
Rejected inputs (before: silently accepted or corrupt output):
/tmp/listwith 129 entries (p001:512throughp129:512) is rejected atthe 129th entry instead of writing past the 128-entry array: