com php-src: Fix bug #77396 - Null Pointer Dereference in phar_create_or_parse_filename: ext/phar/phar.c ext/phar/tests/bug77396.phpt
| From: | Stanislav Malyshev | Date: | Mon, 04 Mar 2019 02:22:32 +0000 |
| Subject: | com php-src: Fix bug #77396 - Null Pointer Dereference in phar_create_or_parse_filename: ext/phar/phar.c ext/phar/tests/bug77396.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104956@lists.php.net to get a copy of this message | ||
Commit: 7f0ab7c20c83a52862ad7c8acf31c3fa739f1274
Author: Stanislav Malyshev <stas@php.net> Sun, 3 Mar 2019 18:22:32 -0800
Parents: 65d81833bbd1de8c38abc591525ebce56bdbd95c
Branches: PHP-7.1 PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7f0ab7c20c83a52862ad7c8acf31c3fa739f1274
Log:
Fix bug #77396 - Null Pointer Dereference in phar_create_or_parse_filename
Bugs:
https://bugs.php.net/77396
Changed paths:
M ext/phar/phar.c
A ext/phar/tests/bug77396.phpt
Diff:
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 0d21731..e117ab0 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -1385,6 +1385,9 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int
a
/* set up our manifest */
mydata = ecalloc(1, sizeof(phar_archive_data));
mydata->fname = expand_filepath(fname, NULL);
+ if (mydata->fname == NULL) {
+ return FAILURE;
+ }
fname_len = strlen(mydata->fname);
#ifdef PHP_WIN32
phar_unixify_path_separators(mydata->fname, fname_len);
diff --git a/ext/phar/tests/bug77396.phpt b/ext/phar/tests/bug77396.phpt
new file mode 100644
index 0000000..f7a2a2f
--- /dev/null
+++ b/ext/phar/tests/bug77396.phpt
@@ -0,0 +1,15 @@
+--TEST--
+Bug #77396 Relative filename exceeding maximum path length causes null pointer dereference.
+--SKIPIF--
+<?php if (!extension_loaded("phar")) die("skip"); ?>
+--FILE--
+<?php
+$path = '../' . str_repeat("x", PHP_MAXPATHLEN) . '.tar';
+$phar = new PharData($path);
+?>
+--EXPECTF--
+Fatal error: Uncaught UnexpectedValueException: Phar creation or opening failed in
%s/bug77396.php:%d
+Stack trace:
+#0 %s/bug77396.php(%d): PharData->__construct(%s)
+#1 {main}
+ thrown in %s/bug77396.php on line %d