diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index d12c4913820..c814545464c 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -51,7 +51,7 @@ PHAR_FUNC(phar_opendir) /* {{{ */ char *name; efree(entry); - entry = filename; + entry = estrndup(filename, filename_len); /* fopen within phar, if :// is not in the url, then prepend phar:/// */ entry_len = filename_len; if (strstr(entry, "://")) { @@ -70,11 +70,9 @@ PHAR_FUNC(phar_opendir) /* {{{ */ stream = php_stream_opendir(name, REPORT_ERRORS, context); efree(name); if (!stream) { - efree(entry); goto skip_phar; } php_stream_to_zval(stream, return_value); - efree(entry); return; } } diff --git a/ext/phar/tests/opendir.phpt b/ext/phar/tests/opendir.phpt new file mode 100644 index 00000000000..62dd9d64964 --- /dev/null +++ b/ext/phar/tests/opendir.phpt @@ -0,0 +1,32 @@ +--TEST-- +Phar: test opendir() interception +--SKIPIF-- + +--INI-- +phar.require_hash=1 +phar.readonly=0 +--FILE-- +'; +$a['dir/file1.txt'] = 'hi'; +$a['dir/file2.txt'] = 'hi2'; +$a['dir/file3.txt'] = 'hi3'; +$a->setStub(' +===DONE=== +--CLEAN-- + +--EXPECT-- +file1.txtfile2.txtfile3.txt===DONE=== \ No newline at end of file