php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41255 move_uploaded_file wrong permissions cgi
Submitted: 2007-05-02 00:22 UTC Modified: 2007-05-02 10:46 UTC
From: agrimm61 at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.4.6 OS: Linux
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: agrimm61 at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-02 00:22 UTC] agrimm61 at gmail dot com
Description:
------------
When moving an uploaded file with move_uploaded_file while php is running in cgi mode the originated file has permissions 600. copy() creates a file with the expected permissions 644. 
As a result the webserver isn't able to read the file.
Safe_Mode is off!

Reproduce code:
---------------
<?
    echo umask();
    copy($_FILES['userfile']['tmp_name'], "./".$_FILES['userfile']['name'].".copy");
    move_uploaded_file($_FILES['userfile']['tmp_name'], "./".$_FILES['userfile']['name']);

?>

Expected result:
----------------
output of 18 which is the right umask ( 022 ), so permissions should be set to 644.

file moved by copy has permissions 644
file moved by move_uploaded_file has permissions 644

Actual result:
--------------
output of 18 which is the right umask ( 022 ), so permissions should be set to 644.

file moved by copy has permissions 644
file moved by move_uploaded_file has permissions 600

As a hint i added some lines in basic_functions.c to get the expected behaviour. Here is the patch :


--- ext/standard/basic_functions.c.orig 2007-01-01 10:46:47.000000000 +0100
+++ ext/standard/basic_functions.c      2007-05-02 01:43:22.000000000 +0200
@@ -2867,10 +2867,12 @@

        VCWD_UNLINK(Z_STRVAL_PP(new_path));
        if (rename(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path)) == 0) {
+               VCWD_CHMOD(Z_STRVAL_PP(new_path),420);
                successful = 1;
        } else
                if (php_copy_file(Z_STRVAL_PP(path), Z_STRVAL_PP(new_path) TSRMLS_CC) == SUCCESS) {
                VCWD_UNLINK(Z_STRVAL_PP(path));
+               VCWD_CHMOD(Z_STRVAL_PP(new_path),420);
                successful = 1;
        }


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-02 10:46 UTC] tony2001@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 03:01:32 2024 UTC