From: Dmitry Stogov Date: Mon, 22 Oct 2007 07:37:52 +0000 (+0000) Subject: Fixed move_uploaded_file() to always set file permissions of resulting file according... X-Git-Tag: RELEASE_2_0_0a1~1562 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29ee7ac05d8c7afdbd41a704dea8bc2cfd779810;p=php Fixed move_uploaded_file() to always set file permissions of resulting file according to UMASK (Andrew Sitnikov) --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 4b2d3b9eff..84be7c7bd3 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -52,6 +52,11 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; #include #include +#ifndef PHP_WIN32 +#include +#include +#endif + #ifdef NETWARE #include #endif @@ -6050,6 +6055,10 @@ PHP_FUNCTION(move_uploaded_file) zval **pp_new_path; zend_bool successful = 0; +#ifndef PHP_WIN32 + int oldmask; int ret; +#endif + if (!SG(rfc1867_uploaded_files)) { RETURN_FALSE; } @@ -6079,6 +6088,16 @@ PHP_FUNCTION(move_uploaded_file) VCWD_UNLINK(new_path); if (VCWD_RENAME(old_path, new_path) == 0) { successful = 1; +#ifndef PHP_WIN32 + oldmask = umask(077); + umask(oldmask); + + ret = VCWD_CHMOD(new_path, 0666 & ~oldmask); + + if (ret == -1) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno)); + } +#endif } else if (php_copy_file_ex(old_path, new_path, STREAM_DISABLE_OPEN_BASEDIR TSRMLS_CC) == SUCCESS) { VCWD_UNLINK(old_path); successful = 1;