php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #77396
Patch issue-77396-npe revision 2019-02-13 04:50 UTC by bishop@php.net
Patch issue-77396-npe.patch revision 2019-02-11 16:07 UTC by bishop@php.net

Patch issue-77396-npe for PHAR related Bug #77396

Patch version 2019-02-13 04:50 UTC

Return to Bug #77396 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: bishop@php.net

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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC