]> granicus.if.org Git - php/commitdiff
Fixed bug #32160 (file truncation in copy() when source & destination are
authorIlia Alshanetsky <iliaa@php.net>
Thu, 3 Mar 2005 03:29:23 +0000 (03:29 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 3 Mar 2005 03:29:23 +0000 (03:29 +0000)
the same).

ext/standard/file.c

index 196bf3d6ec7dc70507055924520da4fe16549631..a371dac4913fa75be69290594a3a9d90c5ae25a4 100644 (file)
@@ -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);