part: Check partition parsed partition type before setting it#1168
part: Check partition parsed partition type before setting it#1168vojtechtrefny wants to merge 1 commit intostoraged-project:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdded stricter validation in set_part_type(): numeric parsing now verifies full-string consumption and rejects unknown MBR partition types; resources are released on validation failure. Also expanded tests with three invalid partition-id cases to assert error handling. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/plugins/part.c`:
- Around line 1775-1781: The early-return path after calling
fdisk_parttype_is_unknown(ptype) leaks the parsed parttype; before returning
FALSE you must unref the allocated ptype by calling fdisk_unref_parttype(ptype)
(similar to the other early-return paths), so update the block that currently
calls fdisk_unref_partition(pa) and returns to also call
fdisk_unref_parttype(ptype) to free the resource while still setting the error
using type_str/BD_PART_ERROR_INVAL.
- Around line 1775-1781: The fdisk_parttype_is_unknown check is being applied
unconditionally and thus rejects structurally-valid custom GPT GUIDs; restrict
this validation to MSDOS/MBR only by moving or wrapping the
fdisk_parttype_is_unknown call (the block that sets BD_PART_ERROR_INVAL and
returns FALSE) so it only runs when table_type == BD_PART_TABLE_MSDOS (the same
scope where fdisk_label_parse_parttype is used for MBR); ensure
bd_part_set_part_type continues to accept unknown GPT parttypes parsed by
fdisk_label_parse_parttype and does not trigger the invalid-type error for GPT.
In `@tests/part_test.py`:
- Around line 1315-1318: The test using
BlockDev.part_set_part_id(self.loop_devs[0], ps.path, "83;id") is unreliable
because "83;id" can be parsed as decimal 83 (0x53) and may be present in
libfdisk’s MBR table; change the input to a value that cannot be interpreted as
a single-byte type such as "0x83;id" (or otherwise replace with an out-of-range
token like "0xfff") so fdisk_label_parse_parttype() will fail consistently and
the with self.assertRaises(GLib.GError): assertion around
BlockDev.part_set_part_id will reliably trigger; update or add a short comment
next to the test explaining the rationale.
0e6cd37 to
6e63d2c
Compare
6e63d2c to
a42600f
Compare
tbzatek
left a comment
There was a problem hiding this comment.
Converting type_str to int back and forth is kinda nasty, but would require deeper refactoring. Good for now though.
Summary by CodeRabbit
Bug Fixes
Tests