Skip to content

Commit 6d60ed6

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix bug #77586 - phar_tar_writeheaders_int() buffer overflow
2 parents e3f7c35 + 3e8d8f7 commit 6d60ed6

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

ext/phar/tar.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,12 @@ static int phar_tar_writeheaders_int(phar_entry_info *entry, void *argument) /*
764764
header.typeflag = entry->tar_type;
765765

766766
if (entry->link) {
767-
strncpy(header.linkname, entry->link, strlen(entry->link));
767+
if (strlcpy(header.linkname, entry->link, sizeof(header.linkname)) >= sizeof(header.linkname)) {
768+
if (fp->error) {
769+
spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, link \"%s\" is too long for format", entry->phar->fname, entry->link);
770+
}
771+
return ZEND_HASH_APPLY_STOP;
772+
}
768773
}
769774

770775
strncpy(header.magic, "ustar", sizeof("ustar")-1);

ext/phar/tests/bug71488.phpt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ DONE
1313
<?php
1414
@unlink(__DIR__."/bug71488.test");
1515
?>
16-
--EXPECT--
17-
DONE
16+
--EXPECTF--
17+
Fatal error: Uncaught BadMethodCallException: tar-based phar "%s/bug71488.test" cannot be created, link "%s" is too long for format in %sbug71488.php:%d
18+
Stack trace:%A

ext/phar/tests/bug77586.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Bug #77586 Symbolic link names in tar-formatted phar must be less than 100 bytes.
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar") || true /* blocked by bug 65332 */) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
$dir = __DIR__."/bug77586";
8+
$phar = new PharData($dir . "/bug77586.tar");
9+
$phar->buildFromDirectory($dir . "/files");
10+
?>
11+
--CLEAN--
12+
<?php
13+
$dir = __DIR__."/bug77586";
14+
unlink($dir . "/bug77586.tar");
15+
?>
16+
--EXPECTF--
17+
Fatal error: Uncaught PharException: tar-based phar "%s/bug77586.tar" cannot be created, link "%s" is too long for format %s
18+
Stack trace:
19+
#0 %s/bug77586.php(%d): PharData->buildFromDirectory('%s')
20+
#1 {main}
21+
thrown in %s/bug77586.php %s on line %d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

0 commit comments

Comments
 (0)