From 0350017680c7540a0a4d9c24f326a4ad70cfac72 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 17 Mar 2023 13:24:47 +0000 Subject: [PATCH] util: Fix path pattern matching with characters after stars Signed-off-by: Michael Tremer --- src/libpakfire/util.c | 9 ++++++++- tests/libpakfire/util.c | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 9819149e8..05795e765 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -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; } diff --git a/tests/libpakfire/util.c b/tests/libpakfire/util.c index 50276a2cb..54d6df0d1 100644 --- a/tests/libpakfire/util.c +++ b/tests/libpakfire/util.c @@ -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; -- 2.39.5