systemd icon indicating copy to clipboard operation
systemd copied to clipboard

boot: devicetree_get_compatible() loop bound uses byte offset instead of word count

Open mil1200 opened this issue 7 months ago • 0 comments

In src/boot/devicetree.c:144:

size_t size_words = struct_size / sizeof(uint32_t);

for (size_t i = 0; i < end; i++) {
        switch (be32toh(cursor[i])) {

end is struct_off + struct_size (a byte offset), but cursor[i] indexes uint32_t words. The loop runs up to end iterations instead of size_words, reading past the struct block.

The default: return NULL case catches most OOB reads after a single word, but if the OOB data happens to match FDT_NOP (0x00000004), scanning continues silently.

Fix: change i < end to i < size_words.

mil1200 avatar Apr 11 '26 08:04 mil1200