]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Add null check to string in archive_pathmatch 1488/head
authorOliver Ford <ojford@gmail.com>
Wed, 27 Jan 2021 14:39:42 +0000 (14:39 +0000)
committerOliver Ford <ojford@gmail.com>
Wed, 27 Jan 2021 14:39:42 +0000 (14:39 +0000)
Adds a null check for the string parameter in archive_pathmatch
and archive_pathmatch_w to prevent a null pointer dereference.

Reported in github issue #1483.

libarchive/archive_pathmatch.c
libarchive/test/test_archive_pathmatch.c

index 619e2b622a3ca0c596c02cf0ce3971d83b2e9df0..0867a268eefe3581bac4a3d79b1f5907b6456db1 100644 (file)
@@ -384,6 +384,8 @@ __archive_pathmatch(const char *p, const char *s, int flags)
        /* Empty pattern only matches the empty string. */
        if (p == NULL || *p == '\0')
                return (s == NULL || *s == '\0');
+       else if (s == NULL)
+               return (0);
 
        /* Leading '^' anchors the start of the pattern. */
        if (*p == '^') {
@@ -424,6 +426,8 @@ __archive_pathmatch_w(const wchar_t *p, const wchar_t *s, int flags)
        /* Empty pattern only matches the empty string. */
        if (p == NULL || *p == L'\0')
                return (s == NULL || *s == L'\0');
+       else if (s == NULL)
+               return (0);
 
        /* Leading '^' anchors the start of the pattern. */
        if (*p == L'^') {
index 21cbdd7e078031f3fdf9857d9d2958c3e5d2cf4e..0116df0288d28e80d464cf56af01a2aeae2fadf8 100644 (file)
@@ -52,6 +52,10 @@ DEFINE_TEST(test_archive_pathmatch)
        assertEqualInt(0, archive_pathmatch("a/b/c", "a/b/", 0));
        assertEqualInt(0, archive_pathmatch("a/b/c", "a/b", 0));
 
+    /* Null string and non-empty pattern returns false. */
+       assertEqualInt(0, archive_pathmatch("a/b/c", NULL, 0));
+       assertEqualInt(0, archive_pathmatch_w(L"a/b/c", NULL, 0));
+
        /* Empty pattern only matches empty string. */
        assertEqualInt(1, archive_pathmatch("","", 0));
        assertEqualInt(0, archive_pathmatch("","a", 0));