Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,11 @@ PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_
php_stream_statbuf src_s, dest_s;
int src_stat_flags = (src_flags & STREAM_DISABLE_OPEN_BASEDIR) ? PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR : 0;

if (!dest||!*dest) {
zend_argument_value_error(2, "cannot be empty");
return FAILURE;
}
Comment thread
arshidkv12 marked this conversation as resolved.
Outdated

switch (php_stream_stat_path_ex(src, src_stat_flags, &src_s, ctx)) {
case -1:
/* non-statable stream */
Expand Down
31 changes: 31 additions & 0 deletions ext/standard/tests/file/copy_empty_path.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
copy() throws ValueError when source or destination is empty
--FILE--
<?php

$dir = __DIR__;

file_put_contents($dir . "/foo.txt", "test");

try {
copy("", $dir . "/bar.txt");
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
copy($dir . "/foo.txt", "");
} catch (ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--CLEAN--
<?php
$dir = __DIR__;
@unlink($dir . "/foo.txt");
@unlink($dir . "/bar.txt");
?>
--EXPECT--
Path must not be empty
copy(): Argument #2 ($to) cannot be empty
Loading