Merge pull request #2775 from AZero13/off-by-one
[tar] Bounds check newdir_len
(cherry picked from commit 26c769ecdc)
This commit is contained in:
1 parent
7f4314ca47
commit
30ca142b35
1 file changed
+4
-1
+4
-1
@@ -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';
|
||||
|
||||
Reference in new issue
Block a user