From: Jakub Jelen Date: Wed, 23 Oct 2019 12:51:41 +0000 (+0200) Subject: modules: Implement correct search in list X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=298ad811540c538fea1906528fe8cf8a6784e5ee;p=p11-kit modules: Implement correct search in list 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 --- diff --git a/p11-kit/modules.c b/p11-kit/modules.c index 39e1fda..2fa53ae 100644 --- a/p11-kit/modules.c +++ b/p11-kit/modules.c @@ -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