Skip to content

Commit ac73c9d

Browse files
committed
Fixed the context parameter on copy() to actually have an effect
# After looking at the logs, Jani did a bad merge into 5.3, so that # the context parameter sent to copy() actually isn't used at all. This # relatively simple patch fixes that for trunk. # # See FR #42965 # internals: # This changes the php_copy_*() decls to contain an additional parameter for stream contexts
1 parent 0cc2946 commit ac73c9d

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

ext/standard/basic_functions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,6 +1206,7 @@ ZEND_END_ARG_INFO()
12061206
ZEND_BEGIN_ARG_INFO(arginfo_copy, 0)
12071207
ZEND_ARG_INFO(0, source_file)
12081208
ZEND_ARG_INFO(0, destination_file)
1209+
ZEND_ARG_INFO(0, context)
12091210
ZEND_END_ARG_INFO()
12101211

12111212
ZEND_BEGIN_ARG_INFO(arginfo_fread, 0)
@@ -5715,7 +5716,7 @@ PHP_FUNCTION(move_uploaded_file)
57155716
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", strerror(errno));
57165717
}
57175718
#endif
5718-
} else if (php_copy_file_ex(path, new_path, STREAM_DISABLE_OPEN_BASEDIR TSRMLS_CC) == SUCCESS) {
5719+
} else if (php_copy_file_ex(path, new_path, STREAM_DISABLE_OPEN_BASEDIR, NULL TSRMLS_CC) == SUCCESS) {
57195720
VCWD_UNLINK(path);
57205721
successful = 1;
57215722
}

ext/standard/file.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ PHP_FUNCTION(copy)
16461646

16471647
context = php_stream_context_from_zval(zcontext, 0);
16481648

1649-
if (php_copy_file(source, target TSRMLS_CC) == SUCCESS) {
1649+
if (php_copy_file_ex(source, target, 0, context TSRMLS_CC) == SUCCESS) {
16501650
RETURN_TRUE;
16511651
} else {
16521652
RETURN_FALSE;
@@ -1656,19 +1656,19 @@ PHP_FUNCTION(copy)
16561656

16571657
PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC) /* {{{ */
16581658
{
1659-
return php_copy_file_ex(src, dest, 0 TSRMLS_CC);
1659+
return php_copy_file_ex(src, dest, 0, NULL TSRMLS_CC);
16601660
}
16611661
/* }}} */
16621662

16631663
/* {{{ php_copy_file
16641664
*/
1665-
PHPAPI int php_copy_file_ex(char *src, char *dest, int src_flg TSRMLS_DC)
1665+
PHPAPI int php_copy_file_ex(char *src, char *dest, int src_flg, php_stream_context *ctx TSRMLS_DC)
16661666
{
16671667
php_stream *srcstream = NULL, *deststream = NULL;
16681668
int ret = FAILURE;
16691669
php_stream_statbuf src_s, dest_s;
16701670

1671-
switch (php_stream_stat_path_ex(src, 0, &src_s, NULL)) {
1671+
switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
16721672
case -1:
16731673
/* non-statable stream */
16741674
goto safe_to_copy;
@@ -1683,7 +1683,7 @@ PHPAPI int php_copy_file_ex(char *src, char *dest, int src_flg TSRMLS_DC)
16831683
return FAILURE;
16841684
}
16851685

1686-
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, NULL)) {
1686+
switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET, &dest_s, ctx)) {
16871687
case -1:
16881688
/* non-statable stream */
16891689
goto safe_to_copy;
@@ -1733,13 +1733,13 @@ PHPAPI int php_copy_file_ex(char *src, char *dest, int src_flg TSRMLS_DC)
17331733
}
17341734
safe_to_copy:
17351735

1736-
srcstream = php_stream_open_wrapper(src, "rb", src_flg | REPORT_ERRORS, NULL);
1736+
srcstream = php_stream_open_wrapper_ex(src, "rb", src_flg | REPORT_ERRORS, NULL, ctx);
17371737

17381738
if (!srcstream) {
17391739
return ret;
17401740
}
17411741

1742-
deststream = php_stream_open_wrapper(dest, "wb", REPORT_ERRORS, NULL);
1742+
deststream = php_stream_open_wrapper_ex(dest, "wb", REPORT_ERRORS, NULL, ctx);
17431743

17441744
if (srcstream && deststream) {
17451745
ret = php_stream_copy_to_stream_ex(srcstream, deststream, PHP_STREAM_COPY_ALL, NULL);

ext/standard/file.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ PHP_MINIT_FUNCTION(user_streams);
7575
PHPAPI int php_le_stream_context(void);
7676
PHPAPI int php_set_sock_blocking(int socketd, int block TSRMLS_DC);
7777
PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC);
78-
PHPAPI int php_copy_file_ex(char *src, char *dest, int src_chk TSRMLS_DC);
78+
PHPAPI int php_copy_file_ex(char *src, char *dest, int src_chk, php_stream_context *ctx TSRMLS_DC);
7979
PHPAPI int php_mkdir_ex(char *dir, long mode, int options TSRMLS_DC);
8080
PHPAPI int php_mkdir(char *dir, long mode TSRMLS_DC);
8181
PHPAPI void php_fgetcsv(php_stream *stream, char delimiter, char enclosure, char escape_char, size_t buf_len, char *buf, zval *return_value TSRMLS_DC);

0 commit comments

Comments
 (0)