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:
Greg Beaver 2008-04-14 16:26:01 +00:00
parent 07e36f5cad
commit eb252c5c92
3 changed files with 11 additions and 2 deletions

View File

@ -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);

View File

@ -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===

View File

@ -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;