From 9c9a8ade39bddd416683410acbb5bdbc0ea2f23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Bollo?= Date: Mon, 20 Jan 2014 15:58:20 +0100 Subject: Fix a bug in search of keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function '_vconf_keylist_lookup' coulded return a node that was not matching the requested 'keyname'. For example, searching the key "acl" in a list containing "aclxxxx", "acl" would return the node "aclxxx" instead of "acl". Also compute the length to be compared only one time, not at each turn of the loop. Change-Id: Id26e9d0eace311e5537fbce075f912d0a263f31d Signed-off-by: José Bollo --- vconf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vconf.c b/vconf.c index a6af153..d1474b1 100755 --- a/vconf.c +++ b/vconf.c @@ -156,6 +156,7 @@ static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname, keynode_t **before_keynode) { keynode_t *found_node, *temp_node = NULL; + size_t length = 1 + strlen(keyname); found_node = _vconf_keylist_headnode(keylist); @@ -165,7 +166,7 @@ static keynode_t *_vconf_keylist_lookup(keylist_t *keylist, const char *keyname, return NULL; } - if (!strncmp(keyname, found_node->keyname, strlen(keyname))) { + if (!memcmp(keyname, found_node->keyname, length)) { if (before_keynode) { *before_keynode = temp_node; } -- cgit v1.2.3