Skip to content

fix(fdt_mut): do not panic on unreferenced bytes in the strings block - #111

Open
calef wants to merge 1 commit into
google:mainfrom
calef:fix-add-property-unreferenced-strings
Open

calef wants to merge 1 commit into
google:mainfrom
calef:fix-add-property-unreferenced-strings

Conversation

@calef

@calef calef commented Nov 11, 2026

Copy link
Copy Markdown

find_existing_string now compares raw bytes, as libfdt's fdt_find_string_ does: it splits the strings block at each null terminator, compares each terminated piece with the name, and skips a trailing piece with no terminator. Bytes that are not a valid string can then never match and never panic.

The new test covers an unterminated byte, a terminated byte that is not UTF-8, and a name that already exists before the invalid bytes, which is reused.

Fixes #109

`Fdt::new` validates only the strings that a property's `nameoff` points
to, so the `dt_strings` block of an accepted tree may contain bytes that
are not a null-terminated UTF-8 string. `find_existing_string` walked the
whole block and expected every string to be valid, which made
`FdtNodeMut::add_property` panic whenever the new name was not found
before such bytes.

Compare raw bytes instead: split the block at each null terminator,
compare every terminated piece with the name, and skip a trailing piece
without a terminator. A piece that is not a valid string can never equal
a `&str`, so it is passed over and the name is appended as before.

Fixes google#109

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.61%. Comparing base (7662cd1) to head (ade324d).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #111   +/-   ##
=======================================
  Coverage   93.61%   93.61%           
=======================================
  Files          26       26           
  Lines        3428     3428           
=======================================
  Hits         3209     3209           
  Misses        219      219           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FdtNodeMut::add_property panics when the strings block contains an invalid string that no property uses

1 participant