From: Ilia Alshanetsky Date: Thu, 3 Mar 2005 03:29:23 +0000 (+0000) Subject: Fixed bug #32160 (file truncation in copy() when source & destination are X-Git-Tag: RELEASE_0_3~94 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09a8f38e390651133ad93c3a1514552660f17458;p=php Fixed bug #32160 (file truncation in copy() when source & destination are the same). --- diff --git a/ext/standard/file.c b/ext/standard/file.c index 196bf3d6ec..a371dac491 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -1699,6 +1699,12 @@ PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) { php_stream *srcstream = NULL, *deststream = NULL; int ret = FAILURE; + struct stat src_s, dest_s; + + /* safety check to ensure that source & destination files are not the same file */ + if (stat(src, &src_s) || (stat(dest, &dest_s) == 0 && src_s.st_ino == dest_s.st_ino)) { + return ret; + } srcstream = php_stream_open_wrapper(src, "rb", STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS, NULL);