php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21032 move_uploaded_file() behavior gives inconsistant file permissions
Submitted: 2002-12-15 17:35 UTC Modified: 2014-12-30 10:41 UTC
Votes:5
Avg. Score:4.4 ± 0.8
Reproduced:4 of 5 (80.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: tcarter at noggin dot com dot au Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 4.2.3 OS: Redhat Linux
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tcarter at noggin dot com dot au
New email:
PHP Version: OS:

 

 [2002-12-15 17:35 UTC] tcarter at noggin dot com dot au
move_uploaded_file() preserves permissions when the source   
& destination are on the same filesystem, but if they are   
on different filesystems sets them to (0777 & ~umask).    
    
In ext/standard/basic_functions.c move_uploaded_file()  
tries to use rename() which preserves permissions, but if  
that fails it uses php_copy_file() then unlink() which  
does not preserve the permissions.    
    
I believe that the behaviour should be consistant whether    
the source and destination are on the same filesystem or    
not (eg if php_copy_file() is used the destination should    
be chmod()ed to match the source's permissions after the   
copy)    
    
    

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-06-12 01:11 UTC] pprocacci at datapipe dot com
I am by no means a c programmer, but if php streams are implemented the way I think they are, then the following patch might prove useful.  Don't blame me if it doesn't work  ;P  This patch is obviously and completly untested.  src and dest in _php_stream_copy_to_stream are already open stream, so in theory, this should work.  Correct me if I'm wrong.  I'm always willing to know why it wouldn't  ;P

main/streams.c

--- streams.c.bak       Thu Jun 12 02:14:11 2003
+++ streams.c   Thu Jun 12 02:13:08 2003
@@ -1152,6 +1152,7 @@
        size_t readchunk;
        size_t haveread = 0;
        size_t didread;
+       struct stat sb;
 #if HAVE_MMAP
        int srcfd;
 #endif
@@ -1224,7 +1225,7 @@
                        }
                } else {
                        if (maxlen == 0) {
-                               return haveread;
+                               goto ENDF;
                        } else {
                                return 0; /* error */
                        }
@@ -1234,6 +1235,9 @@
                        break;
                }
        }
+       ENDF:
+       if(fstat(src, &sb) != -1)
+               fchmod(dest, st.st_mode & ~(S_ISUID | S_ISGID));
        return haveread;

}
 [2014-04-16 18:00 UTC] levim@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2014-04-16 18:00 UTC] levim@php.net
When moving to a new filesystem, what if you don't the permission to change the permissions?
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 05:01:28 2024 UTC