summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2019-03-03 23:33:48 -0800
committerChristoph M. Becker <cmbecker69@gmx.de>2019-03-04 13:19:02 +0100
commit4e676c7b1cac51ae98ff9b31f0e9d5ef2a10b18d (patch)
treec83aec962988ff67ab651c717e3693b5ee033aa1
parente0a7e0670ab6172eef0a2bd424169b11dced1071 (diff)
downloadphp-git-4e676c7b1cac51ae98ff9b31f0e9d5ef2a10b18d.tar.gz
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix bug #77586 - phar_tar_writeheaders_int() buffer overflow (cherry picked from commit 6d60ed69a107aa31c5318d47ed773fe3e9708b8c)
-rw-r--r--ext/phar/tar.c7
-rw-r--r--ext/phar/tests/bug71488.phpt5
-rw-r--r--ext/phar/tests/bug77586.phpt21
-rw-r--r--ext/phar/tests/bug77586/files/link-nktarAMLdJBv7BGYnpzg-ZDycSpWN3Ne3kacltOSE-EqfhStJ1EoBpGuoua6VE-dne29hvpNWXiVbepwIf8-NRHWM9LITLo3nXZnKVNC1
4 files changed, 31 insertions, 3 deletions
diff --git a/ext/phar/tar.c b/ext/phar/tar.c
index 5b5b796ffe..7004676e0b 100644
--- a/ext/phar/tar.c
+++ b/ext/phar/tar.c
@@ -764,7 +764,12 @@ static int phar_tar_writeheaders_int(phar_entry_info *entry, void *argument) /*
header.typeflag = entry->tar_type;
if (entry->link) {
- strncpy(header.linkname, entry->link, strlen(entry->link));
+ if (strlcpy(header.linkname, entry->link, sizeof(header.linkname)) >= sizeof(header.linkname)) {
+ if (fp->error) {
+ spprintf(fp->error, 4096, "tar-based phar \"%s\" cannot be created, link \"%s\" is too long for format", entry->phar->fname, entry->link);
+ }
+ return ZEND_HASH_APPLY_STOP;
+ }
}
strncpy(header.magic, "ustar", sizeof("ustar")-1);
diff --git a/ext/phar/tests/bug71488.phpt b/ext/phar/tests/bug71488.phpt
index 53f1304343..9c58d89488 100644
--- a/ext/phar/tests/bug71488.phpt
+++ b/ext/phar/tests/bug71488.phpt
@@ -13,5 +13,6 @@ DONE
<?php
@unlink(__DIR__."/bug71488.test");
?>
---EXPECT--
-DONE
+--EXPECTF--
+Fatal error: Uncaught BadMethodCallException: tar-based phar "%s/bug71488.test" cannot be created, link "%s" is too long for format in %sbug71488.php:%d
+Stack trace:%A \ No newline at end of file
diff --git a/ext/phar/tests/bug77586.phpt b/ext/phar/tests/bug77586.phpt
new file mode 100644
index 0000000000..039cc16994
--- /dev/null
+++ b/ext/phar/tests/bug77586.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #77586 Symbolic link names in tar-formatted phar must be less than 100 bytes.
+--SKIPIF--
+<?php if (!extension_loaded("phar") || true /* blocked by bug 65332 */) die("skip"); ?>
+--FILE--
+<?php
+$dir = __DIR__."/bug77586";
+$phar = new PharData($dir . "/bug77586.tar");
+$phar->buildFromDirectory($dir . "/files");
+?>
+--CLEAN--
+<?php
+$dir = __DIR__."/bug77586";
+unlink($dir . "/bug77586.tar");
+?>
+--EXPECTF--
+Fatal error: Uncaught PharException: tar-based phar "%s/bug77586.tar" cannot be created, link "%s" is too long for format %s
+Stack trace:
+#0 %s/bug77586.php(%d): PharData->buildFromDirectory('%s')
+#1 {main}
+ thrown in %s/bug77586.php %s on line %d
diff --git a/ext/phar/tests/bug77586/files/link-nktarAMLdJBv7BGYnpzg-ZDycSpWN3Ne3kacltOSE-EqfhStJ1EoBpGuoua6VE-dne29hvpNWXiVbepwIf8-NRHWM9LITLo3nXZnKVNC b/ext/phar/tests/bug77586/files/link-nktarAMLdJBv7BGYnpzg-ZDycSpWN3Ne3kacltOSE-EqfhStJ1EoBpGuoua6VE-dne29hvpNWXiVbepwIf8-NRHWM9LITLo3nXZnKVNC
new file mode 100644
index 0000000000..1de565933b
--- /dev/null
+++ b/ext/phar/tests/bug77586/files/link-nktarAMLdJBv7BGYnpzg-ZDycSpWN3Ne3kacltOSE-EqfhStJ1EoBpGuoua6VE-dne29hvpNWXiVbepwIf8-NRHWM9LITLo3nXZnKVNC
@@ -0,0 +1 @@
+target \ No newline at end of file