All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
To: linux-hotplug@vger.kernel.org
Subject: [PATCH] fix bug in name_list_key_add()
Date: Fri, 05 Sep 2008 13:49:34 +0000	[thread overview]
Message-ID: <48C138EE.1000408@tuffmail.co.uk> (raw)

The search for an existing key e.g. FOO would match longer keys e.g. FOOBAR.
Reuse the correct code from name_list_remove().

diff --git a/udev/udev_utils.c b/udev/udev_utils.c
index f63a9fa..9b6ba24 100644
--- a/udev/udev_utils.c
+++ b/udev/udev_utils.c
@@ -89,14 +89,17 @@ struct name_entry *name_list_key_add(struct list_head *name_list, const char *ke
 {
 	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("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("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));



             reply	other threads:[~2008-09-05 13:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-05 13:49 Alan Jenkins [this message]
2008-09-08 19:52 ` [PATCH] fix bug in name_list_key_add() Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48C138EE.1000408@tuffmail.co.uk \
    --to=alan-jenkins@tuffmail.co.uk \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.