diff --git a/src/libsystemd/sd-hwdb/sd-hwdb.c b/src/libsystemd/sd-hwdb/sd-hwdb.c index 996f253fd90..ba3be260e00 100644 --- a/src/libsystemd/sd-hwdb/sd-hwdb.c +++ b/src/libsystemd/sd-hwdb/sd-hwdb.c @@ -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; diff --git a/test/fuzz/fuzz-hwdb/overlong-fnmatch-key b/test/fuzz/fuzz-hwdb/overlong-fnmatch-key new file mode 100644 index 00000000000..a1850c9d7d0 Binary files /dev/null and b/test/fuzz/fuzz-hwdb/overlong-fnmatch-key differ