Skip to content

Commit 7f0ab7c

Browse files
committed
Fix bug #77396 - Null Pointer Dereference in phar_create_or_parse_filename
1 parent 65d8183 commit 7f0ab7c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ext/phar/phar.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,9 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a
13851385
/* set up our manifest */
13861386
mydata = ecalloc(1, sizeof(phar_archive_data));
13871387
mydata->fname = expand_filepath(fname, NULL);
1388+
if (mydata->fname == NULL) {
1389+
return FAILURE;
1390+
}
13881391
fname_len = strlen(mydata->fname);
13891392
#ifdef PHP_WIN32
13901393
phar_unixify_path_separators(mydata->fname, fname_len);

ext/phar/tests/bug77396.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #77396 Relative filename exceeding maximum path length causes null pointer dereference.
3+
--SKIPIF--
4+
<?php if (!extension_loaded("phar")) die("skip"); ?>
5+
--FILE--
6+
<?php
7+
$path = '../' . str_repeat("x", PHP_MAXPATHLEN) . '.tar';
8+
$phar = new PharData($path);
9+
?>
10+
--EXPECTF--
11+
Fatal error: Uncaught UnexpectedValueException: Phar creation or opening failed in %s/bug77396.php:%d
12+
Stack trace:
13+
#0 %s/bug77396.php(%d): PharData->__construct(%s)
14+
#1 {main}
15+
thrown in %s/bug77396.php on line %d

0 commit comments

Comments
 (0)