]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Bounds check newdir_len 2775/head
authorAZero13 <gfunni234@gmail.com>
Wed, 5 Nov 2025 00:02:08 +0000 (19:02 -0500)
committerAZero13 <gfunni234@gmail.com>
Wed, 5 Nov 2025 00:02:08 +0000 (19:02 -0500)
Honestly, this is of little consequence; if old_len is too big the program will crash anyway. However, an error exists just in case.

tar/util.c

index fc5e15cb039f202858007df304db90df9073f4dd..6e41e49de133361449aaa4d19f0c4fb9cec51ae0 100644 (file)
@@ -314,7 +314,10 @@ set_chdir(struct bsdtar *bsdtar, const char *newdir)
                /* The -C /foo -C bar case; concatenate */
                char *old_pending = bsdtar->pending_chdir;
                size_t old_len = strlen(old_pending);
-        size_t new_len = old_len + strlen(newdir) + 2;
+               size_t newdir_len = strlen(newdir);
+               size_t new_len = old_len + newdir_len + 2;
+               if (old_len > SIZE_MAX - newdir_len - 2)
+                   lafe_errc(1, errno, "Path too long");
                bsdtar->pending_chdir = malloc(new_len);
                if (old_pending[old_len - 1] == '/')
                        old_pending[old_len - 1] = '\0';