]> git.ipfire.org Git - pakfire.git/commitdiff
filelist: Make pattern matching less eager
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Dec 2022 13:19:59 +0000 (13:19 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 9 Dec 2022 13:19:59 +0000 (13:19 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c

index ec1951d33f6b3e75f5627bddfae356cf00aba8ca..8d38aff01454f67ad7731aa707cb56c2a12435ac 100644 (file)
@@ -175,6 +175,7 @@ static int is_glob(const char* s) {
 }
 
 static int pakfire_filelist_match_patterns(const char* path, const char** patterns) {
+       int flags = 0;
        int r;
 
        for (const char** pattern = patterns; *pattern; pattern++) {
@@ -186,7 +187,20 @@ static int pakfire_filelist_match_patterns(const char* path, const char** patter
                if (!is_glob(*pattern))
                        continue;
 
-               r = fnmatch(*pattern, path, 0);
+               // Reset flags
+               flags = 0;
+
+               /*
+                       fnmatch is way too eager for patterns line /usr/lib/*.so which will also match
+                       things like /usr/lib/python3.x/blah/blubb.so.
+                       To prevent this for absolute file paths, we set the FNM_FILE_NAME flag so that
+                       asterisk (*) won't match any slashes (/).
+               */
+               if (**pattern == '/')
+                       flags |= FNM_FILE_NAME;
+
+               // Perform matching
+               r = fnmatch(*pattern, path, flags);
 
                // Found a match
                if (r == 0)