]> git.ipfire.org Git - pakfire.git/commitdiff
util: path_matches: Check if pattern is shorter than string
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 16 Mar 2023 19:27:28 +0000 (19:27 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 16 Mar 2023 19:27:28 +0000 (19:27 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/util.c
tests/libpakfire/util.c

index a972e96bf56b3cf704ec5765db25a2ad6dd3cd05..9819149e8d0a6f0f548e4f0a08f3115800bf7397 100644 (file)
@@ -227,6 +227,10 @@ int pakfire_path_match(const char* p, const char* s) {
                }
        }
 
+       // There are unmatched characters left
+       if (*s)
+               return 0;
+
        // We reached the end of the string and all characters matched
        return 1;
 }
index 37ec2685412f557995e77bb8f0da92e3a156893a..cea03ba3101803064c30bdd482b8161c5d3f9071 100644 (file)
@@ -91,6 +91,9 @@ static int test_path_match(const struct test* t) {
        ASSERT_ERRNO(pakfire_path_match("/usr/***", "/usr/bin"), EINVAL);
        ASSERT_ERRNO(pakfire_path_match("/usr/***", "/usr/bin/bash"), EINVAL);
 
+       // Partial paths shouldn't match
+       ASSERT_FALSE(pakfire_path_match("/usr", "/usr/bin/bash"));
+
        return EXIT_SUCCESS;
 
 FAIL: