systemd
systemd copied to clipboard
boot: devicetree_get_compatible() loop bound uses byte offset instead of word count
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.