Repository navigation
Add fuzz target for fdt_mut - #167
vishruthasgowda wants to merge 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #167 +/- ##
=======================================
Coverage 95.32% 95.32%
=======================================
Files 27 27
Lines 4040 4040
=======================================
Hits 3851 3851
Misses 189 189 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
m4tx
left a comment
There was a problem hiding this comment.
Thanks for this, it seems pretty good to me! I've left a few comments, PTAL.
|
Thanks for the review! I've addressed all the comments:
PTAL. |
m4tx
left a comment
There was a problem hiding this comment.
Thanks, this looks much better now. A few comments before we merge this.
| } | ||
|
|
||
| fn assert_valid(fdt: &FdtMut<&mut [u8]>) { | ||
| Fdt::new(fdt.as_read_only().data()).expect("FDT must stay valid after every operation"); |
There was a problem hiding this comment.
Let's validate with Fdt::with_options(fdt.as_read_only().data(), FdtOptions::new().max_depth(usize::MAX)) - otherwise, subsequent AddNode operations could potentially exceed the default 64 depth limit.
| forget_subtree(paths, &path); | ||
| } | ||
| } | ||
| Op::Compact => fdt.compact(), |
There was a problem hiding this comment.
Let's also assert here that the new size is smaller than the old one, and that another compact() call doesn't change the blob.
| return; | ||
| }; | ||
| assert!(n.remove_child(&name), "existing child must be removed"); | ||
| assert!(n.child(&name).is_none()); |
There was a problem hiding this comment.
This check can fail on the following chain of operations:
- AddNode adds "a"
- AddNode adds "a@0"
- RemoveNode with "a" removes the first node it finds with or without address, so the "a" node
n.child("a")still returns the "a@0" node, and this check fails.
I've double checked and this is consistent with libfdt, so we want to keep this behaviour.
Let's change this check to something like assert!(!n.children().any(|c| c.name() == name)) to enforce equal-name check in case of a scenario described above.
| let Some(n) = fdt.find_node_mut(&path) else { | ||
| return; | ||
| }; | ||
| if n.remove().is_ok() { |
There was a problem hiding this comment.
n.remove() should succeed on any non-root node (and we check for the "/" path above). Let's .expect() this here.
Adds a fuzz target for fdt_mut.
The target starts from tests/dtb/test_props.dtb with some spare buffer space and applies an arbitrary sequence of operations (add_property, set_value, remove_property, remove_child, remove node, compact) on randomly chosen nodes. After every operation it checks that the buffer still parses as a valid FDT, and that each operation has its expected effect (e.g. adding a duplicate property fails, an added property is readable with the same value, remove_* returns true only if the item existed).
Ran for ~2 minutes (~200k executions) locally with no crashes.
Notes / possible follow-ups:
FdtNode::descendants()#114.Fixes #166