mirror of
https://github.com/systemd/systemd.git
synced 2026-08-11 01:25:28 +00:00
hwdb: reject overlong fnmatch key instead of passing NULL to fnmatch()
When the accumulated trie key exceeds the fixed-size line buffer, linebuf_get() returns NULL. trie_fnmatch_f() passed that NULL straight into fnmatch() as the pattern, causing a SIGSEGV on a crafted hwdb.bin (reachable now that recursion is capped rather than overflowing the stack first). Treat the NULL like the other corruption checks and return -EBADMSG. Follow-up for73fea38cf1Fixes https://github.com/systemd/systemd/issues/42376 Co-developed-by: Claude Opus 4.8 <noreply@anthropic.com> (cherry picked from commit3db89cbf0e) (cherry picked from commit138565f8d6) (cherry picked from commite6337757b5)
This commit is contained in:
@@ -203,12 +203,18 @@ static int trie_fnmatch_f(sd_hwdb *hwdb, const struct trie_node_f *node, size_t
|
||||
linebuf_rem_char(buf);
|
||||
}
|
||||
|
||||
if (le64toh(node->values_count) && fnmatch(linebuf_get(buf), search, 0) == 0)
|
||||
for (i = 0; i < le64toh(node->values_count); i++) {
|
||||
err = hwdb_add_property(hwdb, trie_node_value(hwdb, node, i));
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
if (le64toh(node->values_count) != 0) {
|
||||
const char *line = linebuf_get(buf);
|
||||
if (!line)
|
||||
return -EBADMSG;
|
||||
|
||||
if (fnmatch(line, search, 0) == 0)
|
||||
for (i = 0; i < le64toh(node->values_count); i++) {
|
||||
err = hwdb_add_property(hwdb, trie_node_value(hwdb, node, i));
|
||||
if (err < 0)
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
linebuf_rem(buf, len);
|
||||
return 0;
|
||||
|
||||
BIN
test/fuzz/fuzz-hwdb/overlong-fnmatch-key
Normal file
BIN
test/fuzz/fuzz-hwdb/overlong-fnmatch-key
Normal file
Binary file not shown.
Reference in New Issue
Block a user