]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util: Fix the logic in ms_fnmatch_protocol()
authorAndreas Schneider <asn@samba.org>
Thu, 26 Oct 2017 07:47:57 +0000 (09:47 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 2 Mar 2018 13:07:14 +0000 (14:07 +0100)
Make sure we always pass a valid max_n pointer to ms_fnmatch_core().

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: David Disseldorp <ddiss@samba.org>
lib/util/ms_fnmatch.c

index c0f61ab04e75da6880918d21d5aab82fe5b82589..636ac399f66e421c69f5ec8a71337709dd7656fb 100644 (file)
@@ -164,7 +164,8 @@ static int ms_fnmatch_core(const char *p, const char *n,
 int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
                        bool is_case_sensitive)
 {
-       int ret, count, i;
+       int ret = -1;
+       size_t count, i;
 
        if (strcmp(string, "..") == 0) {
                string = ".";
@@ -209,13 +210,17 @@ int ms_fnmatch_protocol(const char *pattern, const char *string, int protocol,
                if (pattern[i] == '*' || pattern[i] == '<') count++;
        }
 
-       {
+       /* If the pattern includes '*' or '<' */
+       if (count >= 1) {
                struct max_n max_n[count];
 
                memset(max_n, 0, sizeof(struct max_n) * count);
 
                ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.'),
                                      is_case_sensitive);
+       } else {
+               ret = ms_fnmatch_core(pattern, string, NULL, strrchr(string, '.'),
+                                     is_case_sensitive);
        }
 
        return ret;