php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24873 open_basedir doesn't work for single `/'
Submitted: 2003-07-30 10:50 UTC Modified: 2005-01-31 22:53 UTC
From: enrik dot berkhan at planb dot de Assigned:
Status: Closed Package: Safe Mode/open_basedir
PHP Version: 4.3.2 OS: any
Private report: No CVE-ID:
 [2003-07-30 10:50 UTC] enrik dot berkhan at planb dot de
Description:
------------
if you set open_basedir = "/" it doesn't work, as it is internally expanded to "//" in fopen_wrappers.c.

Suggested patch:

*** fopen_wrappers.c.orig       Sun Feb 23 23:03:54 2003
--- fopen_wrappers.c    Wed Jul 30 17:38:41 2003
***************
*** 131,137 ****
        /* Resolve the real path into resolved_name */
        if ((expand_filepath(path, resolved_name TSRMLS_CC) != NULL) && (expand_filepath(local_open_basedir, resolved_basedir TSRMLS_CC) != NULL)) {
                /* Handler for basedirs that end with a / */
!               if (basedir[strlen(basedir)-1] == PHP_DIR_SEPARATOR) {
                        resolved_basedir_len = strlen(resolved_basedir);
                        resolved_basedir[resolved_basedir_len] = '/';
                        resolved_basedir[++resolved_basedir_len] = '\0';
--- 131,138 ----
        /* Resolve the real path into resolved_name */
        if ((expand_filepath(path, resolved_name TSRMLS_CC) != NULL) && (expand_filepath(local_open_basedir, resolved_basedir TSRMLS_CC) != NULL)) {
                /* Handler for basedirs that end with a / */
!               if (basedir[strlen(basedir)-1] == PHP_DIR_SEPARATOR &&
!                     resolved_basedir[strlen(resolved_basedir)-1] != PHP_DIR_SEPARATOR) {
                        resolved_basedir_len = strlen(resolved_basedir);
                        resolved_basedir[resolved_basedir_len] = '/';
                        resolved_basedir[++resolved_basedir_len] = '\0';
***************
*** 139,145 ****
                        resolved_basedir_len = strlen(resolved_basedir);
                }
                                                                                
!               if (path[strlen(path)-1] == PHP_DIR_SEPARATOR) {
                        resolved_name_len = strlen(resolved_name);
                        resolved_name[resolved_name_len] = '/';
                        resolved_name[++resolved_name_len] = '\0';
--- 140,147 ----
                        resolved_basedir_len = strlen(resolved_basedir);
                }
   
!               if (path[strlen(path)-1] == PHP_DIR_SEPARATOR &&
!                     resolved_name[strlen(resolved_name)-1] != PHP_DIR_SEPARATOR) {
                        resolved_name_len = strlen(resolved_naPHP_DIR_SEPARATORme);
                        resolved_name[resolved_name_len] = '/';
                        resolved_name[++resolved_name_len] = '\0';

BTW, why is a literal `/' added to the names, not PHP_DIR_SEPARATOR?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-30 12:56 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.

The path resolving logic dealing with addition of / is there for *nix based systems that always use / as the directory separator.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 18:01:58 2014 UTC