mirror of
https://github.com/php/php-src.git
synced 2024-09-23 02:47:26 +00:00
fix potential segfault if some idiot tries to remove the root directory of a phar, add creation of root directory to test
This commit is contained in:
parent
07e36f5cad
commit
eb252c5c92
@ -582,7 +582,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path + 1), 2, &error TSRMLS_CC))) {
|
||||
if (!(entry = phar_get_entry_info_dir(phar, resource->path + 1, strlen(resource->path) - 1, 2, &error TSRMLS_CC))) {
|
||||
if (error) {
|
||||
php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: cannot remove directory \"%s\" in phar \"%s\", %s", resource->path+1, resource->host, error);
|
||||
efree(error);
|
||||
|
@ -46,6 +46,9 @@ rmdir('phar://' . dirname(__FILE__) . '/unknown.phar/hi');
|
||||
ini_set('phar.readonly', 1);
|
||||
rmdir($pname . '/another/dir');
|
||||
ini_set('phar.readonly', 0);
|
||||
rmdir($pname);
|
||||
rmdir($pname . '/');
|
||||
mkdir($pname . '/');
|
||||
?>
|
||||
===DONE===
|
||||
--CLEAN--
|
||||
@ -80,4 +83,10 @@ Warning: rmdir(): phar error: cannot remove directory "phar://", no phar archive
|
||||
Warning: rmdir(): phar error: cannot remove directory "hi" in phar "%sunknown.phar", directory does not exist in %sdir.php on line %d
|
||||
|
||||
Warning: rmdir(): phar error: cannot rmdir directory "phar://%sdir.phar.php/another/dir", write operations disabled in %sdir.php on line %d
|
||||
|
||||
Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
|
||||
|
||||
Warning: rmdir(): phar error: cannot remove directory "" in phar "%sdir.phar.php", directory does not exist in %sdir.php on line %d
|
||||
|
||||
Warning: mkdir(): phar error: cannot create directory "" in phar "%sdir.phar.php", phar error: invalid path "" must not be empty in %sdir.php on line %d
|
||||
===DONE===
|
@ -982,7 +982,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in
|
||||
{
|
||||
const char *pcr_error;
|
||||
phar_entry_info *entry;
|
||||
char is_dir = (path[path_len - 1] == '/');
|
||||
char is_dir = path_len && (path[path_len - 1] == '/');
|
||||
|
||||
if (error) {
|
||||
*error = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user