cvs: php-src / NEWS /ext/standard file.c /ext/standard/tests/file bug32160.phpt bug32160.txt

From: Date: Wed, 22 Jun 2005 16:13:48 +0000
Subject: cvs: php-src / NEWS /ext/standard file.c /ext/standard/tests/file bug32160.phpt bug32160.txt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-32477@lists.php.net to get a copy of this message
iliaa Wed Jun 22 12:13:48 2005 EDT Added files: /php-src/ext/standard/tests/file bug32160.phpt bug32160.txt Modified files: /php-src NEWS /php-src/ext/standard file.c Log: Fixed bug #32160 (copying a file into itself leads to data loss). http://cvs.php.net/diff.php/php-src/NEWS?r1=1.1949&r2=1.1950&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.1949 php-src/NEWS:1.1950 --- php-src/NEWS:1.1949 Wed Jun 22 11:26:05 2005 +++ php-src/NEWS Wed Jun 22 12:13:44 2005 @@ -43,6 +43,7 @@ - Fixed bug #31256 (PHP_EVAL_LIBLINE configure macro does not handle -pthread). (Jani) - Fixed bug #31213 (Sideeffects caused by fix of bug #29493). (Dmitry) +- Fixed bug #32160 (copying a file into itself leads to data loss). (Ilia) - Fixed bug #31054 (safe_mode & open_basedir checks only check first include_path value). (Ilia) - Fixed bug #29683 (headers_list() returns empty array). (Tony) http://cvs.php.net/diff.php/php-src/ext/standard/file.c?r1=1.406&r2=1.407&ty=u Index: php-src/ext/standard/file.c diff -u php-src/ext/standard/file.c:1.406 php-src/ext/standard/file.c:1.407 --- php-src/ext/standard/file.c:1.406 Wed Apr 6 09:57:30 2005 +++ php-src/ext/standard/file.c Wed Jun 22 12:13:47 2005 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.406 2005/04/06 13:57:30 iliaa Exp $ */ +/* $Id: file.c,v 1.407 2005/06/22 16:13:47 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1700,6 +1700,56 @@ { php_stream *srcstream = NULL, *deststream = NULL; int ret = FAILURE; + php_stream_statbuf src_s, dest_s; + + switch (php_stream_stat_path_ex(src, 0, &src_s, NULL)) { + 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_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, NULL) != 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, NULL); 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) 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

« previous php.cvs (#32477) next »