php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #643 BUG in SAFE MODE. Can create files in directories not own by script
Submitted: 1998-08-10 21:04 UTC Modified: 1998-09-22 11:08 UTC
From: mcduff at prentice dot uq dot edu dot au Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.2a OS: DU 4.0
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mcduff at prentice dot uq dot edu dot au
New email:
PHP Version: OS:

 

 [1998-08-10 21:04 UTC] mcduff at prentice dot uq dot edu dot au
I was experiment with safe mode on 3.0.2a (Apache-1.3.0 on DU4.0) and found 
something unexpected. I was working on a script to create a new file in a 
directory owned by the script and writable by the web server (running under 
http). I found that I could create a file even though the directory was owned 
as someone other than the script owner (but still writable by the web server).

I tracked this down to  php3_fopen_wrapper routine in fopen-wrappers.c where a 
call was made to _php3_checkuid(path, 1). My query is that this should be 
_php3_checkuid(path, 2). as well

My quick patch is

*** fopen-wrappers.c    Tue Aug 11 10:57:15 1998
--- fopen-wrappers.c.orig       Mon Aug 10 16:01:16 1998
***************
*** 108,114 ****
        if (options & USE_PATH && php3_ini.include_path != NULL) {
                return php3_fopen_with_path(path, mode, php3_ini.include_path, NULL);
        } else {
!               if (options & ENFORCE_SAFE_MODE && php3_ini.safe_mode && !(_php3_checkuid(path, 1)&&_php3_checkuid(path, 2))) {
                        php3_error(E_WARNING, "SAFE MODE Restriction in effect.  Invalid owner of file to be read.");
                        return NULL;
                }
--- 108,114 ----
        if (options & USE_PATH && php3_ini.include_path != NULL) {
                return php3_fopen_with_path(path, mode, php3_ini.include_path, NULL);
        } else {
!               if (options & ENFORCE_SAFE_MODE && php3_ini.safe_mode && (!_php3_checkuid(path, 1))) {
                        php3_error(E_WARNING, "SAFE MODE Restriction in effect.  Invalid owner of file to be read.");
                        return NULL;
                }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-09-22 11:08 UTC] rasmus
Fixed in 3.0.4.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 09:01:33 2025 UTC