mirror of
https://github.com/php/php-src.git
synced 2025-08-19 08:49:28 +02:00
fix Bug #46032: PharData::__construct wrong memory read
This commit is contained in:
parent
92a547c7e4
commit
e7b6fe1b45
2 changed files with 36 additions and 3 deletions
|
@ -1165,10 +1165,10 @@ PHP_METHOD(Phar, __construct)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
save_fname = fname;
|
||||||
if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, !is_data, 2 TSRMLS_CC)) {
|
if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, !is_data, 2 TSRMLS_CC)) {
|
||||||
/* use arch (the basename for the archive) for fname instead of fname */
|
/* use arch (the basename for the archive) for fname instead of fname */
|
||||||
/* this allows support for RecursiveDirectoryIterator of subdirectories */
|
/* this allows support for RecursiveDirectoryIterator of subdirectories */
|
||||||
save_fname = fname;
|
|
||||||
#ifdef PHP_WIN32
|
#ifdef PHP_WIN32
|
||||||
phar_unixify_path_separators(arch, arch_len);
|
phar_unixify_path_separators(arch, arch_len);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1178,7 +1178,6 @@ PHP_METHOD(Phar, __construct)
|
||||||
} else {
|
} else {
|
||||||
arch = estrndup(fname, fname_len);
|
arch = estrndup(fname, fname_len);
|
||||||
arch_len = fname_len;
|
arch_len = fname_len;
|
||||||
save_fname = fname;
|
|
||||||
fname = arch;
|
fname = arch;
|
||||||
phar_unixify_path_separators(arch, arch_len);
|
phar_unixify_path_separators(arch, arch_len);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1186,7 +1185,7 @@ PHP_METHOD(Phar, __construct)
|
||||||
|
|
||||||
if (phar_open_or_create_filename(fname, fname_len, alias, alias_len, is_data, REPORT_ERRORS, &phar_data, &error TSRMLS_CC) == FAILURE) {
|
if (phar_open_or_create_filename(fname, fname_len, alias, alias_len, is_data, REPORT_ERRORS, &phar_data, &error TSRMLS_CC) == FAILURE) {
|
||||||
|
|
||||||
if (fname == arch) {
|
if (fname == arch && fname != save_fname) {
|
||||||
efree(arch);
|
efree(arch);
|
||||||
fname = save_fname;
|
fname = save_fname;
|
||||||
}
|
}
|
||||||
|
|
34
ext/phar/tests/bug46032.phpt
Normal file
34
ext/phar/tests/bug46032.phpt
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
--TEST--
|
||||||
|
Phar: bug #46032: PharData::__construct wrong memory read
|
||||||
|
--SKIPIF--
|
||||||
|
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
||||||
|
<?php if (getenv('SKIP_SLOW_TESTS')) die('skip'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$a = __DIR__ .'/mytest';
|
||||||
|
|
||||||
|
try {
|
||||||
|
new phar($a);
|
||||||
|
} catch (exception $e) { }
|
||||||
|
|
||||||
|
var_dump($a);
|
||||||
|
|
||||||
|
try {
|
||||||
|
new phar($a);
|
||||||
|
} catch (exception $e) { }
|
||||||
|
|
||||||
|
var_dump($a);
|
||||||
|
|
||||||
|
new phardata('0000000000000000000');
|
||||||
|
?>
|
||||||
|
===DONE===
|
||||||
|
--EXPECTF--
|
||||||
|
string(%d) "%smytest"
|
||||||
|
string(%d) "%smytest"
|
||||||
|
|
||||||
|
Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '0000000000000000000', file extension (or combination) not recognised' in %sbug46032.php:%d
|
||||||
|
Stack trace:
|
||||||
|
#0 /home/cellog/workspace/php5/ext/phar/tests/bug46032.php(%d): PharData->__construct('000000000000000...')
|
||||||
|
#1 {main}
|
||||||
|
thrown in %sbug46032.php on line %d
|
Loading…
Add table
Add a link
Reference in a new issue