From: Tim Kientzle Date: Sat, 9 May 2026 20:49:25 +0000 (-0700) Subject: Merge pull request #2928 from stoeckmann/anchor_no_flags X-Git-Tag: v3.8.8~127 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=cfbbd2bf44b914714fe41ea2e382a871baf32e10;p=thirdparty%2Flibarchive.git Merge pull request #2928 from stoeckmann/anchor_no_flags pathmatch: Treat anchors not special without flags (cherry picked from commit 5ed0b5ea88bbe75e1e5e6e273724433bd59e5736) --- diff --git a/libarchive/archive_pathmatch.c b/libarchive/archive_pathmatch.c index f65f43745..4b69ae1e4 100644 --- a/libarchive/archive_pathmatch.c +++ b/libarchive/archive_pathmatch.c @@ -399,7 +399,7 @@ __archive_pathmatch(const char *p, const char *s, int flags) return (0); /* Leading '^' anchors the start of the pattern. */ - if (*p == '^') { + if ((flags & PATHMATCH_NO_ANCHOR_START) && *p == '^') { ++p; flags &= ~PATHMATCH_NO_ANCHOR_START; } @@ -444,7 +444,7 @@ __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags) return (0); /* Leading '^' anchors the start of the pattern. */ - if (*p == L'^') { + if ((flags & PATHMATCH_NO_ANCHOR_START) && *p == L'^') { ++p; flags &= ~PATHMATCH_NO_ANCHOR_START; } diff --git a/libarchive/test/test_archive_match_path.c b/libarchive/test/test_archive_match_path.c index ce48263f7..527413db7 100644 --- a/libarchive/test/test_archive_match_path.c +++ b/libarchive/test/test_archive_match_path.c @@ -233,8 +233,8 @@ test_inclusion_mbs(void) return; } - /* Test for pattern "^aa*" */ - assertEqualIntA(m, 0, archive_match_include_pattern(m, "^aa*")); + /* Test for pattern "aa*" */ + assertEqualIntA(m, 0, archive_match_include_pattern(m, "aa*")); /* Test with 'aa1234', which should not be excluded. */ archive_entry_copy_pathname(ae, "aa1234"); @@ -282,8 +282,8 @@ test_inclusion_wcs(void) return; } - /* Test for pattern "^aa*" */ - assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"^aa*")); + /* Test for pattern "aa*" */ + assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"aa*")); /* Test with 'aa1234', which should not be excluded. */ archive_entry_copy_pathname(ae, "aa1234"); @@ -383,8 +383,8 @@ test_exclusion_and_inclusion(void) } assertEqualIntA(m, 0, archive_match_exclude_pattern(m, "^aaa*")); - assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"^aa*")); - assertEqualIntA(m, 0, archive_match_include_pattern(m, "^a1*")); + assertEqualIntA(m, 0, archive_match_include_pattern_w(m, L"aa*")); + assertEqualIntA(m, 0, archive_match_include_pattern(m, "a1*")); /* Test with 'aa1234', which should not be excluded. */ archive_entry_copy_pathname(ae, "aa1234"); @@ -413,13 +413,13 @@ test_exclusion_and_inclusion(void) /* Verify unmatched inclusion patterns. */ assertEqualIntA(m, ARCHIVE_OK, archive_match_path_unmatched_inclusions_next(m, &mp)); - assertEqualString("^a1*", mp); + assertEqualString("a1*", mp); assertEqualIntA(m, ARCHIVE_EOF, archive_match_path_unmatched_inclusions_next(m, &mp)); /* Verify unmatched inclusion patterns again in Wide-Char. */ assertEqualIntA(m, ARCHIVE_OK, archive_match_path_unmatched_inclusions_next_w(m, &wp)); - assertEqualWString(L"^a1*", wp); + assertEqualWString(L"a1*", wp); assertEqualIntA(m, ARCHIVE_EOF, archive_match_path_unmatched_inclusions_next_w(m, &wp)); diff --git a/libarchive/test/test_archive_pathmatch.c b/libarchive/test/test_archive_pathmatch.c index 3b212aca9..ea75851db 100644 --- a/libarchive/test/test_archive_pathmatch.c +++ b/libarchive/test/test_archive_pathmatch.c @@ -56,6 +56,10 @@ DEFINE_TEST(test_archive_pathmatch) assertEqualInt(0, archive_pathmatch_w(L"a/b/c", NULL, 0)); /* Empty pattern only matches empty string. */ + assertEqualInt(1, archive_pathmatch(NULL,NULL, 0)); + assertEqualInt(1, archive_pathmatch(NULL,"", 0)); + assertEqualInt(0, archive_pathmatch(NULL,"a", 0)); + assertEqualInt(1, archive_pathmatch("",NULL, 0)); assertEqualInt(1, archive_pathmatch("","", 0)); assertEqualInt(0, archive_pathmatch("","a", 0)); assertEqualInt(1, archive_pathmatch("*","", 0)); @@ -76,11 +80,15 @@ DEFINE_TEST(test_archive_pathmatch) assertEqualInt(0, archive_pathmatch("a", "ab", 0)); assertEqualInt(0, archive_pathmatch("a", "ab", 0)); assertEqualInt(1, archive_pathmatch("a?c", "abc", 0)); + assertEqualInt(1, archive_pathmatch("*a", "/a", 0)); + assertEqualInt(1, archive_pathmatch("*a", "a", 0)); /* SUSv2: ? matches / */ assertEqualInt(1, archive_pathmatch("a?c", "a/c", 0)); assertEqualInt(1, archive_pathmatch("a?*c*", "a/c", 0)); assertEqualInt(1, archive_pathmatch("*a*", "a/c", 0)); assertEqualInt(1, archive_pathmatch("*a*", "/a/c", 0)); + assertEqualInt(0, archive_pathmatch("*a", "/a/c", 0)); + assertEqualInt(0, archive_pathmatch("*a", "a/c", 0)); assertEqualInt(1, archive_pathmatch("*a*", "defaaaaaaa", 0)); assertEqualInt(0, archive_pathmatch("a*", "defghi", 0)); assertEqualInt(0, archive_pathmatch("*a*", "defghi", 0)); @@ -201,6 +209,14 @@ DEFINE_TEST(test_archive_pathmatch) failure("Trailing '/.' is still the same directory."); assertEqualInt(1, archive_pathmatch("./abc*/./def", "abc/def/.", 0)); + /* Anchor characters without flags not special. */ + assertEqualInt(0, archive_pathmatch("^abc", "abc", 0)); + assertEqualInt(1, archive_pathmatch("^abc", "^abc", 0)); + assertEqualInt(0, archive_pathmatch("abc$", "abc", 0)); + assertEqualInt(1, archive_pathmatch("abc$", "abc$", 0)); + assertEqualInt(0, archive_pathmatch("^abc$", "abc", 0)); + assertEqualInt(1, archive_pathmatch("^abc$", "^abc$", 0)); + /* Matches not anchored at beginning. */ assertEqualInt(0, archive_pathmatch("bcd", "abcd", PATHMATCH_NO_ANCHOR_START));