diff --git a/ext/standard/file.c b/ext/standard/file.c index a7b73f1fe56eb..4a83edd87c983 100644 --- a/ext/standard/file.c +++ b/ext/standard/file.c @@ -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; + } + switch (php_stream_stat_path_ex(src, src_stat_flags, &src_s, ctx)) { case -1: /* non-statable stream */ diff --git a/ext/standard/tests/file/copy_empty_path.phpt b/ext/standard/tests/file/copy_empty_path.phpt new file mode 100644 index 0000000000000..efa493bc4fbe6 --- /dev/null +++ b/ext/standard/tests/file/copy_empty_path.phpt @@ -0,0 +1,31 @@ +--TEST-- +copy() throws ValueError when source or destination is empty +--FILE-- +getMessage(), PHP_EOL; +} + +try { + copy($dir . "/foo.txt", ""); +} catch (ValueError $e) { + echo $e->getMessage(), PHP_EOL; +} + +?> +--CLEAN-- + +--EXPECT-- +Path must not be empty +copy(): Argument #2 ($to) cannot be empty