X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flibudev%2Flibudev-hwdb.c;h=5645a11437c7d100cd1d177e41ef50d30516d7d1;hb=ddc77f62244bb41d5c8261517e2e1ff1b763fc94;hp=751b34209e6853a4f300d34ed9ee4dd6b9ef5b46;hpb=88a6477ef32ac4c59111f7340525714a6e02e503;p=elogind.git diff --git a/src/libudev/libudev-hwdb.c b/src/libudev/libudev-hwdb.c index 751b34209..5645a1143 100644 --- a/src/libudev/libudev-hwdb.c +++ b/src/libudev/libudev-hwdb.c @@ -140,9 +140,13 @@ static const struct trie_node_f *node_lookup_f(struct udev_hwdb *hwdb, const str } static int hwdb_add_property(struct udev_hwdb *hwdb, const char *key, const char *value) { - /* TODO: add sub-matches (+) against DMI data */ + /* + * Silently ignore all properties which do not start with a + * space; future extensions might use additional prefixes. + */ if (key[0] != ' ') return 0; + if (udev_list_entry_add(&hwdb->properties_list, key+1, value) == NULL) return -ENOMEM; return 0; @@ -169,8 +173,8 @@ static int trie_fnmatch_f(struct udev_hwdb *hwdb, const struct trie_node_f *node linebuf_rem_char(buf); } - if (node->values_count && fnmatch(linebuf_get(buf), search, 0) == 0) - for (i = 0; i < node->values_count; i++) { + 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_string(hwdb, trie_node_values(hwdb, node)[i].key_off), trie_string(hwdb, trie_node_values(hwdb, node)[i].value_off)); if (err < 0) @@ -236,7 +240,7 @@ static int trie_search_f(struct udev_hwdb *hwdb, const char *search) { if (search[i] == '\0') { size_t n; - for (n = 0; n < node->values_count; n++) { + for (n = 0; n < le64toh(node->values_count); n++) { err = hwdb_add_property(hwdb, trie_string(hwdb, trie_node_values(hwdb, node)[n].key_off), trie_string(hwdb, trie_node_values(hwdb, node)[n].value_off)); if (err < 0) @@ -300,11 +304,11 @@ _public_ struct udev_hwdb *udev_hwdb_new(struct udev *udev) { } log_debug("=== trie on-disk ===\n"); - log_debug("tool version: %llu", (unsigned long long)le64toh(hwdb->head->tool_version)); - log_debug("file size: %8llu bytes\n", (unsigned long long)hwdb->st.st_size); - log_debug("header size %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->header_size)); - log_debug("strings %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->strings_len)); - log_debug("nodes %8llu bytes\n", (unsigned long long)le64toh(hwdb->head->nodes_len)); + log_debug("tool version: %"PRIu64, le64toh(hwdb->head->tool_version)); + log_debug("file size: %8llu bytes\n", (unsigned long long) hwdb->st.st_size); + log_debug("header size %8"PRIu64" bytes\n", le64toh(hwdb->head->header_size)); + log_debug("strings %8"PRIu64" bytes\n", le64toh(hwdb->head->strings_len)); + log_debug("nodes %8"PRIu64" bytes\n", le64toh(hwdb->head->nodes_len)); return hwdb; } @@ -377,7 +381,7 @@ bool udev_hwdb_validate(struct udev_hwdb *hwdb) { _public_ struct udev_list_entry *udev_hwdb_get_properties_list_entry(struct udev_hwdb *hwdb, const char *modalias, unsigned int flags) { int err; - if (!hwdb->f) { + if (!hwdb || !hwdb->f) { errno = EINVAL; return NULL; }