Skip to content

Commit

Permalink
dtb: Skip decoding strings if not nul terminated
Browse files Browse the repository at this point in the history
If a property is defined to be a string, make sure it is nul terminated
before decoding it. This fixes a case where <1> int was decoded into
['', '', '', '']. This still will not fix the case where there's the last
byte is nul. There's only so much we can do for garbage in.

Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
robherring committed Mar 4, 2024
1 parent 229ba6b commit da1dcdd
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dtschema/dtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ def prop_value(validator, nodename, p):
return data

if fmt.startswith('string'):
if not data.endswith(b'\0'):
# Wrong data type?, skip decoding to force errors
return data
return data[:-1].decode(encoding='ascii').split('\0')

if {'flag'} & prop_types:
Expand Down

0 comments on commit da1dcdd

Please sign in to comment.