]> granicus.if.org Git - php/commitdiff
fix potential segfault if some idiot tries to remove the root directory of a phar...
authorGreg Beaver <cellog@php.net>
Mon, 14 Apr 2008 16:26:01 +0000 (16:26 +0000)
committerGreg Beaver <cellog@php.net>
Mon, 14 Apr 2008 16:26:01 +0000 (16:26 +0000)
ext/phar/dirstream.c
ext/phar/tests/dir.phpt
ext/phar/util.c

index bdcd3406a97a2ab47486bfe656788fed4f385af4..1bac2d1c9883ecd3b07ded0b548eee8d24d7f82e 100644 (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);
index d74fcd50a3ef4f166a790241dbbf367c2c601cdb..0d77aa5ee53313b445a94dc55bd340fff18ef8b0 100644 (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===
\ No newline at end of file
index f07000df87637c65309fc6943174aaf2f801e350..210088619b03df75ff58d105cc2002309a4c2ae6 100644 (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;