From: Antony Dovgal Date: Tue, 25 Apr 2006 08:41:02 +0000 (+0000) Subject: fix #37191 (chmod takes off sticky bit when safe_mode is On) X-Git-Tag: php-5.1.3~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90b3dadc4ebcfb94b93814559bb286b58ba05f5e;p=php fix #37191 (chmod takes off sticky bit when safe_mode is On) --- diff --git a/NEWS b/NEWS index 682fe05ba5..90d3637a0c 100644 --- 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) diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c index 845b1c574d..8d40561c51 100644 --- a/ext/standard/filestat.c +++ b/ext/standard/filestat.c @@ -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) {