From: Michael Tremer Date: Thu, 16 Mar 2023 19:27:28 +0000 (+0000) Subject: util: path_matches: Check if pattern is shorter than string X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa1a78ec9217006e9ad45e83aa8571bc33ea627d;p=people%2Fstevee%2Fpakfire.git util: path_matches: Check if pattern is shorter than string Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index a972e96b..9819149e 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -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; } diff --git a/tests/libpakfire/util.c b/tests/libpakfire/util.c index 37ec2685..cea03ba3 100644 --- a/tests/libpakfire/util.c +++ b/tests/libpakfire/util.c @@ -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: