com php-src: Merge branch 'PHP-7.1' into PHP-7.2: main/streams/ plain_wrapper.c
| From: | Stanislav Malyshev | Date: | Mon, 04 Mar 2019 17:17:14 +0000 |
| Subject: | com php-src: Merge branch 'PHP-7.1' into PHP-7.2: main/streams/ plain_wrapper.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104998@lists.php.net to get a copy of this message | ||
Commit: 2cc1ab81c2e6bbd877bbe3c501edae20d8b2ae98
Author: Stanislav Malyshev <stas@php.net> Mon, 4 Mar 2019 09:17:14 -0800
Parents: 040196972c7a757200c2e1aa88f360322c38ffde e3133e4db70476fb7adfdedb738483e2255ce0e1
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2cc1ab81c2e6bbd877bbe3c501edae20d8b2ae98
Log:
Merge branch 'PHP-7.1' into PHP-7.2
* PHP-7..1:
Fix bug #77630 - safer rename() procedure
Bugs:
https://bugs..php.net/77630
Changed paths:
MM main/streams/plain_wrapper.c
Diff:
diff --cc main/streams/plain_wrapper.c
index 9b36d00,7fdf906..d409fe9
--- a/main/streams/plain_wrapper.c
+++ b/main/streams/plain_wrapper.c
@@@ -1168,34 -1168,51 +1168,51 @@@ static int php_plain_files_rename(php_s
# ifdef EXDEV
if (errno == EXDEV) {
zend_stat_t sb;
-# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)
- /* not sure what to do in ZTS case, umask is not thread-safe */
++# if !defined(ZTS) && !defined(TSRM_WIN32)
++ /* not sure what to do in ZTS case, umask is not thread-safe */
+ int oldmask = umask(077);
+ # endif
+ int success = 0;
if (php_copy_file(url_from, url_to) == SUCCESS) {
if (VCWD_STAT(url_from, &sb) == 0) {
- # ifndef TSRM_WIN32
- if (VCWD_CHMOD(url_to, sb.st_mode)) {
- if (errno == EPERM) {
- php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
- VCWD_UNLINK(url_from);
- return 1;
- }
+ success = 1;
-# if !defined(TSRM_WIN32) && !defined(NETWARE)
++# if !defined(TSRM_WIN32)
+ /*
+ * Try to set user and permission info on the target.
+ * If we're not root, then some of these may fail.
+ * We try chown first, to set proper group info, relying
+ * on the system environment to have proper umask to not allow
+ * access to the file in the meantime.
+ */
+ if (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {
php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
- return 0;
+ if (errno != EPERM) {
+ success = 0;
+ }
}
- if (VCWD_CHOWN(url_to, sb.st_uid, sb.st_gid)) {
- if (errno == EPERM) {
+
+ if (success) {
+ if (VCWD_CHMOD(url_to, sb.st_mode)) {
php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
- VCWD_UNLINK(url_from);
- return 1;
+ if (errno != EPERM) {
+ success = 0;
+ }
}
- php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
- return 0;
}
# endif
- VCWD_UNLINK(url_from);
- return 1;
+ if (success) {
+ VCWD_UNLINK(url_from);
+ }
+ } else {
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
}
+ } else {
+ php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
}
- php_error_docref2(NULL, url_from, url_to, E_WARNING, "%s", strerror(errno));
- return 0;
-# if !defined(ZTS) && !defined(TSRM_WIN32) && !defined(NETWARE)
++# if !defined(ZTS) && !defined(TSRM_WIN32)
+ umask(oldmask);
+ # endif
+ return success;
}
# endif
#endif