php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | |
Patch issue-77586-buff-overflow for PHAR related Bug #77586Patch version 2019-02-13 05:17 UTC Return to Bug #77586 | Download this patchThis patch renders other patches obsolete Obsolete patches: Patch Revisions:Developer: bishop@php.netdiff --git a/ext/phar/tar.c b/ext/phar/tar.c index 9de3047..20f6882 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -762,7 +762,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/bug77586.phpt b/ext/phar/tests/bug77586.phpt new file mode 100644 index 0000000..039cc16 --- /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 120000 index 0000000..1de5659 --- /dev/null +++ b/ext/phar/tests/bug77586/files/link-nktarAMLdJBv7BGYnpzg-ZDycSpWN3Ne3kacltOSE-EqfhStJ1EoBpGuoua6VE-dne29hvpNWXiVbepwIf8-NRHWM9LITLo3nXZnKVNC @@ -0,0 +1 @@ +target \ No newline at end of file diff --git a/ext/phar/tests/bug77586/files/target b/ext/phar/tests/bug77586/files/target new file mode 100644 index 0000000..e69de29 |
Copyright © 2001-2024 The PHP Group All rights reserved. |
Last updated: Thu Nov 21 14:01:29 2024 UTC |