summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Jenkins <alan-jenkins@tuffmail.co.uk>2008-09-08 21:51:30 +0200
committerKay Sievers <kay.sievers@vrfy.org>2008-09-08 21:51:30 +0200
commitcb8896cd74814acc9360db3156e37233fcfbc20c (patch)
treee16e7e312ef5df706bf21c0d7a17fd064e77533f
parent37a123a9bccd448333fcd83abec926f195dbed9e (diff)
fix name compare bug name_list_key_add()
The search for an existing key e.g. FOO would match longer keys e.g. FOOBAR. Reuse the correct code from name_list_remove().
-rw-r--r--udev/udev_utils.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/udev/udev_utils.c b/udev/udev_utils.c
index 1649b8cbf0..2df8fab1f8 100644
--- a/udev/udev_utils.c
+++ b/udev/udev_utils.c
@@ -89,14 +89,17 @@ struct name_entry *name_list_key_add(struct udev *udev, struct list_head *name_l
{
struct name_entry *name_loop;
struct name_entry *name_new;
+ size_t keylen = strlen(key);
list_for_each_entry(name_loop, name_list, node) {
- if (strncmp(name_loop->name, key, strlen(key)) == 0) {
- dbg(udev, "key already present '%s', replace it\n", name_loop->name);
- snprintf(name_loop->name, sizeof(name_loop->name), "%s=%s", key, value);
- name_loop->name[sizeof(name_loop->name)-1] = '\0';
- return name_loop;
- }
+ if (strncmp(name_loop->name, key, keylen) != 0)
+ continue;
+ if (name_loop->name[keylen] != '=')
+ continue;
+ dbg(udev, "key already present '%s', replace it\n", name_loop->name);
+ snprintf(name_loop->name, sizeof(name_loop->name), "%s=%s", key, value);
+ name_loop->name[sizeof(name_loop->name)-1] = '\0';
+ return name_loop;
}
name_new = malloc(sizeof(struct name_entry));