part: Fix partition ID validation#1177
part: Fix partition ID validation#1177vojtechtrefny wants to merge 1 commit intostoraged-project:masterfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughPartition id parsing in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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.
🧹 Nitpick comments (1)
src/plugins/part.c (1)
1728-1734: Consider usinggint64for clearer signed comparison.The variable
part_id_intis declared asguint64, butg_ascii_strtollreturnsgint64. While the code works correctly (negative inputs like "-1" wrap to large unsigned values caught by> 0xFF), the comparisonpart_id_int <= 0on an unsigned type is effectively justpart_id_int == 0.Using a signed type would make the intent clearer:
♻️ Suggested improvement for type consistency
- guint64 part_id_int = 0; + gint64 part_id_int = 0; /* check if part type/id is valid for MBR */ if (table_type == BD_PART_TABLE_MSDOS) { part_id_int = g_ascii_strtoll (type_str, &endptr, 0); - if (part_id_int <= 0 || part_id_int > 0xFF || endptr == NULL || *endptr != '\0') { + if (part_id_int < 1 || part_id_int > 0xFF || endptr == NULL || *endptr != '\0') {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/plugins/part.c` around lines 1728 - 1734, part_id_int is declared as guint64 but assigned from g_ascii_strtoll (which returns gint64), making the signed comparison part_id_int <= 0 misleading; change the declaration of part_id_int to gint64 (or another signed 64-bit type) so negative parse results are represented correctly, then keep the existing validation logic that checks if part_id_int <= 0 || part_id_int > 0xFF || endptr == NULL || *endptr != '\0' inside the BD_PART_TABLE_MSDOS branch (symbols: part_id_int, g_ascii_strtoll, type_str, endptr, BD_PART_TABLE_MSDOS).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/plugins/part.c`:
- Around line 1728-1734: part_id_int is declared as guint64 but assigned from
g_ascii_strtoll (which returns gint64), making the signed comparison part_id_int
<= 0 misleading; change the declaration of part_id_int to gint64 (or another
signed 64-bit type) so negative parse results are represented correctly, then
keep the existing validation logic that checks if part_id_int <= 0 ||
part_id_int > 0xFF || endptr == NULL || *endptr != '\0' inside the
BD_PART_TABLE_MSDOS branch (symbols: part_id_int, g_ascii_strtoll, type_str,
endptr, BD_PART_TABLE_MSDOS).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 70997a53-f8ab-4a47-8bec-2c207debe14c
📒 Files selected for processing (2)
src/plugins/part.ctests/part_test.py
Follow up for a42600f. We want to be able to set all valid IDs even those unknown to libfdisk.
a7ab00f to
f9e0824
Compare
Follow up for a42600f. We want to be able to set all valid IDs even those unknown to libfdisk.
Summary by CodeRabbit
Bug Fixes
Tests