From: Greg Beaver Date: Sat, 5 Jan 2008 23:02:23 +0000 (+0000) Subject: fix segfault, add separate tar test for readonly=0 on corrupted tar X-Git-Tag: RELEASE_2_0_0a1~1012 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=632a633154f4c86ce6e4c08a2b76e8dc858e83f1;p=php fix segfault, add separate tar test for readonly=0 on corrupted tar --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index ea04444113..da2b861bc6 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1796,9 +1796,9 @@ int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int a php_stream_close(fp); return FAILURE; } + php_stream_close(fp); } - php_stream_close(fp); if (PHAR_G(readonly)) { if (options & REPORT_ERRORS) { @@ -1890,7 +1890,7 @@ int phar_open_filename(char *fname, int fname_len, char *alias, int alias_len, i return FAILURE; } - fp = php_stream_open_wrapper(fname, "rb", IGNORE_URL|STREAM_MUST_SEEK|REPORT_ERRORS, NULL); + fp = php_stream_open_wrapper(fname, "rb", IGNORE_URL|STREAM_MUST_SEEK, NULL); if (!fp) { if (options & REPORT_ERRORS) { diff --git a/ext/phar/tests/tar/tar_001.phpt b/ext/phar/tests/tar/tar_001.phpt index 4e888c0d02..af15609119 100644 --- a/ext/phar/tests/tar/tar_001.phpt +++ b/ext/phar/tests/tar/tar_001.phpt @@ -3,9 +3,6 @@ Phar: tar-based phar corrupted --SKIPIF-- ---INI-- -phar.readonly=0 -phar.require_hash=0 --FILE-- init(); $a->addFile('tar_001.phpt', __FILE__); $a->close(); -$a = fopen('phar://tar_001.phar/tar_001.phpt', 'rb'); +$a = fopen('phar://' . dirname(__FILE__) . '/tar_001.phar/tar_001.phpt', 'rb'); try { -$a = new Phar('tar_001.phar'); +$a = new Phar(dirname(__FILE__) . '/tar_001.phar'); echo "should not execute\n"; } catch (Exception $e) { echo $e->getMessage() . "\n"; @@ -28,6 +25,6 @@ echo $e->getMessage() . "\n"; @unlink(dirname(__FILE__) . '/tar_001.phar'); ?> --EXPECTF-- -Warning: fopen(phar://tar_001.phar/tar_001.phpt): failed to open stream: phar error: "tar_001.phar" is a corrupted tar file in %s/tar_001.php on line %d -Cannot open phar file 'tar_001.phar' with alias '(null)': phar error: "tar_001.phar" is a corrupted tar file +Warning: fopen(phar://%s/tar_001.phar/tar_001.phpt): failed to open stream: phar error: "%s/tar_001.phar" is a corrupted tar file in %s/tar_001.php on line %d +Cannot open phar file '%s/tar_001.phar' with alias '(null)': phar error: "%s/tar_001.phar" is a corrupted tar file ===DONE=== \ No newline at end of file diff --git a/ext/phar/tests/tar/tar_002.phpt b/ext/phar/tests/tar/tar_002.phpt new file mode 100644 index 0000000000..f815dbfe30 --- /dev/null +++ b/ext/phar/tests/tar/tar_002.phpt @@ -0,0 +1,32 @@ +--TEST-- +Phar: tar-based phar corrupted 2 +--SKIPIF-- + + +--INI-- +phar.readonly=0 +--FILE-- +init(); +$a->addFile('tar_002.phpt', __FILE__); +$a->close(); + +$a = fopen('phar://' . dirname(__FILE__) . '/tar_002.phar/tar_002.phpt', 'rb'); +try { +$a = new Phar(dirname(__FILE__) . '/tar_002.phar'); +echo "should not execute\n"; +} catch (Exception $e) { +echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +Warning: fopen(phar://%s/tar_002.phar/tar_002.phpt): failed to open stream: phar error: "%s/tar_002.phar" is a corrupted tar file in %s/tar_002.php on line %d +Cannot open phar file '%s/tar_002.phar' with alias '(null)': phar error: "%s/tar_002.phar" is a corrupted tar file +===DONE=== \ No newline at end of file