iliaa Wed Jul 20 15:26:33 2005 EDT
Added files: (Branch: PHP_4_4)
/php-src/ext/standard/tests/file bug32160.txt bug32160.phpt
Modified files:
/php-src NEWS
/php-src/ext/standard file.c
Log:
MFH: Fixed bug #32160 (copying a file into itself leads to data loss).
http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1247.2.920.2.17&r2=1.1247.2.920.2.18&ty=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.1247.2.920.2.17 php-src/NEWS:1.1247.2.920.2.18
--- php-src/NEWS:1.1247.2.920.2.17 Tue Jul 19 21:45:03 2005
+++ php-src/NEWS Wed Jul 20 15:26:30 2005
@@ -1,10 +1,11 @@
PHP 4 NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2005, Version 4.4.1
-- Fixed bug #33648 (Using --with-regex=system causes compile failure). (Andrei)
- Fixed bug #33673 (Added detection for partially uploaded files). (Ilia)
+- Fixed bug #33648 (Using --with-regex=system causes compile failure). (Andrei)
- Fixed bug #33156 (cygwin version of setitimer doesn't accept ITIMER_PROF).
(Nuno)
+- Fixed bug #32160 (copying a file into itself leads to data loss). (Ilia)
- Fixed bug #31158 (array_splice on $GLOBALS crashes). (Dmitry)
11 Jul 2005, Version 4.4.0
http://cvs.php.net/diff.php/php-src/ext/standard/file.c?r1=1.279.2.70&r2=1.279.2.70.2.1&ty=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.279.2.70
php-src/ext/standard/file.c:1.279.2.70.2.1
--- php-src/ext/standard/file.c:1.279.2.70 Sun Mar 27 10:53:59 2005
+++ php-src/ext/standard/file.c Wed Jul 20 15:26:31 2005
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: file.c,v 1.279.2.70 2005/03/27 15:53:59 iliaa Exp $ */
+/* $Id: file.c,v 1.279.2.70.2.1 2005/07/20 19:26:31 iliaa Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -2141,6 +2141,56 @@
{
php_stream *srcstream = NULL, *deststream = NULL;
int ret = FAILURE;
+ php_stream_statbuf src_s, dest_s;
+
+ switch (php_stream_stat_path(src, &src_s)) {
+ case -1:
+ /* non-statable stream */
+ goto safe_to_copy;
+ break;
+ case 0:
+ break;
+ default: /* failed to stat file, does not exist? */
+ return ret;
+ }
+ if (php_stream_stat_path(dest, &dest_s) != 0) {
+ goto safe_to_copy;
+ }
+ if (!src_s.sb.st_ino || !dest_s.sb.st_ino) {
+ goto no_stat;
+ }
+ if (src_s.sb.st_ino == dest_s.sb.st_ino && src_s.sb.st_dev ==
dest_s.sb.st_dev) {
+ return ret;
+ } else {
+ goto safe_to_copy;
+ }
+no_stat:
+ {
+ char *sp, *dp;
+ int res;
+
+ if ((sp = expand_filepath(src, NULL TSRMLS_CC)) == NULL) {
+ return ret;
+ }
+ if ((dp = expand_filepath(dest, NULL TSRMLS_CC)) == NULL) {
+ efree(sp);
+ goto safe_to_copy;
+ }
+
+ res =
+#ifndef PHP_WIN32
+ !strcmp(sp, dp);
+#else
+ !strcasecmp(sp, dp);
+#endif
+
+ efree(sp);
+ efree(dp);
+ if (res) {
+ return ret;
+ }
+ }
+safe_to_copy:
srcstream = php_stream_open_wrapper(src, "rb",
STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS,
http://cvs.php.net/co.php/php-src/ext/standard/tests/file/bug32160.txt?r=1.1&p=1
Index: php-src/ext/standard/tests/file/bug32160.txt
+++ php-src/ext/standard/tests/file/bug32160.txt
copy test
http://cvs.php.net/co.php/php-src/ext/standard/tests/file/bug32160.phpt?r=1.1&p=1
Index: php-src/ext/standard/tests/file/bug32160.phpt
+++ php-src/ext/standard/tests/file/bug32160.phpt
--TEST--
Bug #32160 (copying a file into itself leads to data loss)
--FILE--
<?php
$path = dirname(__FILE__) . "/bug32160.txt";
var_dump(copy($path, $path));
chdir(dirname(__FILE__));
var_dump(copy($path, "bug32160.txt"));
var_dump(copy("bug32160.txt", "bug32160.txt"));
?>
--EXPECT--
bool(false)
bool(false)
bool(false)
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php