From: Tobias Stoeckmann Date: Wed, 18 Mar 2026 10:17:02 +0000 (+0100) Subject: pathmatch: Anchors within pattern not special X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=adf7edd191a36510fa6f9a3bcf63d5a9a5b419ad;p=thirdparty%2Flibarchive.git pathmatch: Anchors within pattern not special The anchor characters ^ and $ have only special meanings if they are located at the beginning (^) or at the end ($) of the pattern. And even then they are supposed to be only special if flags are set. If they are located within the pattern itself, they are regular characters regardless of flags. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_pathmatch.c b/libarchive/archive_pathmatch.c index 19e0889ff..db0d2b791 100644 --- a/libarchive/archive_pathmatch.c +++ b/libarchive/archive_pathmatch.c @@ -202,7 +202,7 @@ pm(const char *p, const char *s, int flags) if (*p == '\0') return (1); while (*s) { - if (archive_pathmatch(p, s, flags)) + if (pm(p, s, flags)) return (1); ++s; } @@ -307,7 +307,7 @@ pm_w(const wchar_t *p, const wchar_t *s, int flags) if (*p == L'\0') return (1); while (*s) { - if (archive_pathmatch_w(p, s, flags)) + if (pm_w(p, s, flags)) return (1); ++s; } diff --git a/libarchive/test/test_archive_pathmatch.c b/libarchive/test/test_archive_pathmatch.c index 3696d38fc..3b212aca9 100644 --- a/libarchive/test/test_archive_pathmatch.c +++ b/libarchive/test/test_archive_pathmatch.c @@ -285,4 +285,22 @@ DEFINE_TEST(test_archive_pathmatch) archive_pathmatch("a/b/c$", "a/b/c/d", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); assertEqualInt(1, archive_pathmatch("b/c/d$", "a/b/c/d", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + + /* Anchor characters within pattern not special. */ + assertEqualInt(0, + archive_pathmatch("*^*", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + archive_pathmatch("*^*", "a^b", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + archive_pathmatch("*$*", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + archive_pathmatch("*$*", "a$b", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + archive_pathmatch("a*/^b/c", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + archive_pathmatch("a*/^b/c", "a/^b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(0, + archive_pathmatch("a*/b$/c", "a/b/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); + assertEqualInt(1, + archive_pathmatch("a*/b$/c", "a/b$/c", PATHMATCH_NO_ANCHOR_START | PATHMATCH_NO_ANCHOR_END)); }