]> granicus.if.org Git - php/commitdiff
fix #37191 (chmod takes off sticky bit when safe_mode is On)
authorAntony Dovgal <tony2001@php.net>
Tue, 25 Apr 2006 08:41:02 +0000 (08:41 +0000)
committerAntony Dovgal <tony2001@php.net>
Tue, 25 Apr 2006 08:41:02 +0000 (08:41 +0000)
NEWS
ext/standard/filestat.c

diff --git a/NEWS b/NEWS
index 682fe05ba531282690ef30dc6205e684afbeede2..90d3637a0c171cf4ac06c5880f35bada9a333d28 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Apr 2006, PHP 5.1.3RC4
-- Fixed bug #37192 (cc fails on hash_adler.c:32). Mike
+- Fixed bug #37192 (cc fails on hash_adler.c:32). (Mike)
+- Fixed bug #37191 (chmod takes off sticky bit when safe_mode is On). (Tony)
 
 20 Apr 2006, PHP 5.1.3RC3
 - Fixed reading stream filters never notified about EOF. (Mike)
index 845b1c574d52425a3c9c51c9dbf5577fe6fac02e..8d40561c51593095c81150a000a93ae6803eb0d5 100644 (file)
@@ -504,8 +504,23 @@ PHP_FUNCTION(chmod)
           Setuiding files could allow users to gain privileges
           that safe mode doesn't give them.
        */
-       if(PG(safe_mode))
-               imode &= 0777;
+
+       if(PG(safe_mode)) {
+               php_stream_statbuf ssb;
+               if (php_stream_stat_path_ex(Z_STRVAL_PP(filename), 0, &ssb, NULL)) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "stat failed for %s", Z_STRVAL_PP(filename));
+                       RETURN_FALSE;
+               }
+               if ((imode & 04000) != 0 && (ssb.sb.st_mode & 04000) == 0) {
+                       imode ^= 04000;
+               }
+               if ((imode & 02000) != 0 && (ssb.sb.st_mode & 02000) == 0) {
+                       imode ^= 02000;
+               }
+               if ((imode & 01000) != 0 && (ssb.sb.st_mode & 01000) == 0) {
+                       imode ^= 01000;
+               }
+       }
 
        ret = VCWD_CHMOD(Z_STRVAL_PP(filename), imode);
        if (ret == -1) {