]> git.ipfire.org Git - pakfire.git/commitdiff
util: Fix path pattern matching with characters after stars
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 17 Mar 2023 13:24:47 +0000 (13:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 17 Mar 2023 13:24:47 +0000 (13:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c
tests/libpakfire/util.c

index 9819149e8d0a6f0f548e4f0a08f3115800bf7397..05795e76592d0ee2ea4f27723485f6e26e6f3325 100644 (file)
@@ -156,6 +156,7 @@ int pakfire_path_exists(const char* path) {
 */
 static int __pakfire_path_match_star(const char* p, const char* s) {
        unsigned int stars = 0;
+       int r;
 
        // Count how many stars we found
        while (p && *p == '*') {
@@ -184,10 +185,16 @@ static int __pakfire_path_match_star(const char* p, const char* s) {
 
                        // Read as many characters as possible
                        default:
-                               continue;
+                               r = pakfire_path_match(p, s);
+                               if (r)
+                                       return r;
                }
        }
 
+       // The pattern has not entirely been consumed
+       if (*p)
+               return 0;
+
        // If we reached the end of the string, * has consumed everything
        return 1;
 }
index 50276a2cbd95a208c0f0731db3810015e869453b..54d6df0d113fc81ff2650fd59af0d454cf983194 100644 (file)
@@ -97,6 +97,7 @@ static int test_path_match(const struct test* t) {
        // Check for stars in the middle
        ASSERT_TRUE(pakfire_path_match("/usr/lib64/*.so.*", "/usr/lib64/libblah.so.1"));
        ASSERT_TRUE(pakfire_path_match("/usr/lib64/**/*.so", "/usr/lib64/blah/module.so"));
+       ASSERT_FALSE(pakfire_path_match("/usr/lib64/*.so.*", "/usr/lib64/beep"));
 
        return EXIT_SUCCESS;