]> granicus.if.org Git - p11-kit/commitdiff
modules: Implement correct search in list
authorJakub Jelen <jjelen@redhat.com>
Wed, 23 Oct 2019 12:51:41 +0000 (14:51 +0200)
committerDaiki Ueno <ueno@gnu.org>
Thu, 24 Oct 2019 08:11:19 +0000 (10:11 +0200)
The current version of matching was failing, when the list contained
also a searched string with some suffix, for example, when we ran from
p11-kit and the p11-kit-proxy was first in the list and p11-kit later,
it was not matched, because the test did not find a separator after
the first match, decided that it does not match and did not try further.

example program p11-kit
example enable-in: p11-kit-proxy,p11-kit

p11-kit/modules.c

index 39e1fdacae268a2193907e2bde3d1058aace9dc7..2fa53ae51c8fbd9e53bd1a2176dddf69e65cd422 100644 (file)
@@ -496,17 +496,27 @@ is_string_in_list (const char *list,
                    const char *string)
 {
        const char *where;
+       const char *start = list;
 
-       where = strstr (list, string);
-       if (where == NULL)
-               return false;
+       while (*start != '\0') {
+               where = strstr (start, string);
+               if (where == NULL)
+                       return false;
 
-       /* Has to be at beginning/end of string, and delimiter before/after */
-       if (where != list && !is_list_delimiter (*(where - 1)))
-               return false;
+               /* Has to be at beginning/end of string, and delimiter before/after */
+               if (where != list && !is_list_delimiter (*(where - 1))) {
+                       start += strlen (string);
+                       continue;
+               }
 
-       where += strlen (string);
-       return (*where == '\0' || is_list_delimiter (*where));
+               where += strlen (string);
+               if (*where == '\0' || is_list_delimiter (*where)) {
+                       return true;
+               }
+               start = where;
+       }
+
+       return false;
 }
 
 static bool