php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44608 Use of rmdir() and relative directory scope / open_basedir restriction
Submitted: 2008-04-02 12:15 UTC Modified: 2008-08-20 01:00 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: adrian dot stannard at icps2007 dot org Assigned: fb-req-jani (profile)
Status: No Feedback Package: Safe Mode/open_basedir
PHP Version: 5.2.5 OS: FreeBSD
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: adrian dot stannard at icps2007 dot org
New email:
PHP Version: OS:

 

 [2008-04-02 12:15 UTC] adrian dot stannard at icps2007 dot org
Description:
------------
Use of rmdir() and relative directory scope / open_basedir restriction.

I cannot find mention of this anywhere, but the following is observed if you are on a server with open_basedir restriction and you use relative links in your script, for e.g. you define a root directory as $root='./';

If you use rmdir($dir), where $dir is some dir relative to your $root, rmdir removes this directory successfully, but later if you perform another file calling function dependent relative to $root - for example if you do a file include you get the following error:

open_basedir restriction in effect
File(./includes/page_header.php) is not within the allowed path(s):
/home/[account_name]:/usr/lib/php:/usr/local/lib/php:/tmp

the $root variable itself is unchanged (I've checked this), but its scope changes. So far I've only seen this happen immediately after using rmdir.

The only way around this seems to be to drop relative assignments and redefine the root as something like:

$root=$_SERVER['DOCUMENT_ROOT']. dirname($_SERVER["PHP_SELF"]).'/';


**Note on server configuration: SAFE MODE is off, but open_basedir restriction has been set **

Reproduce code:
---------------
$selected_dir='some_user_created_directory';

rmdir($root.$selected_dir);

include($root.'some_file.php');

Expected result:
----------------
$selected_dir is deleted.
Would then expect to see some_file.php included.

Actual result:
--------------
open_basedir restriction in effect
File(./includes/page_header.php) is not within the allowed path(s):
/home/[account_name]:/usr/lib/php:/usr/local/lib/php:/tmp

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-12 08:58 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz

There are some fixes done in PHP_5_3 which most likely fix this problem. Note: Those fixes will NOT be backported to 5.2 branch!
 [2008-08-20 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Wed Dec 12 08:01:25 2018 UTC