Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,13 +1439,18 @@ PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_f
/* }}} */

/* {{{ php_copy_file_ctx */
PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx)
ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx)
{
php_stream *srcstream = NULL, *deststream = NULL;
zend_result ret = FAILURE;
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) {
zend_argument_must_not_be_empty_error(2);
return FAILURE;
}

switch (php_stream_stat_path_ex(src, src_stat_flags, &src_s, ctx)) {
case -1:
/* non-statable stream */
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PHP_MINIT_FUNCTION(user_streams);

PHPAPI zend_result php_copy_file(const char *src, const char *dest);
PHPAPI zend_result php_copy_file_ex(const char *src, const char *dest, int src_flags);
PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx);
ZEND_ATTRIBUTE_NONNULL_ARGS(1,2) PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_flags, php_stream_context *ctx);
PHPAPI void php_fstat(php_stream *stream, zval *return_value);
PHPAPI void php_flock_common(php_stream *stream, zend_long operation, uint32_t operation_arg_num,
zval *wouldblock, zval *return_value);
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) must not be empty
Loading