Skip to content

Commit 8bf2d58

Browse files
committed
Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex
Otherwise we can get open_basedir warnings from the stat call while still performing the actual copy. Fixes GH-11138 Closes GH-11156
1 parent f0149c5 commit 8bf2d58

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
- PGSQL:
99
. Fixed parameter parsing of pg_lo_export(). (kocsismate)
1010

11+
- Standard:
12+
. Fixed bug GH-11138 (move_uploaded_file() emits open_basedir warning for
13+
source file). (ilutov)
14+
1115
11 May 2023, PHP 8.1.19
1216

1317
- Core:

Zend/tests/gh11138.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
move_uploaded_file() emits open_basedir warning for source file
3+
--POST_RAW--
4+
Content-type: multipart/form-data, boundary=AaB03x
5+
6+
--AaB03x
7+
content-disposition: form-data; name="file"; filename="file.txt"
8+
Content-Type: text/plain
9+
10+
foo
11+
--AaB03x--
12+
--FILE--
13+
<?php
14+
15+
ini_set('open_basedir', __DIR__);
16+
17+
$destination = __DIR__ . '/gh11138.tmp';
18+
var_dump(move_uploaded_file($_FILES['file']['tmp_name'], $destination));
19+
echo file_get_contents($destination), "\n";
20+
21+
?>
22+
--CLEAN--
23+
<?php
24+
@unlink(__DIR__ . '/gh11138.tmp');
25+
?>
26+
--EXPECT--
27+
bool(true)
28+
foo

ext/standard/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1669,8 +1669,9 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
16691669
php_stream *srcstream = NULL, *deststream = NULL;
16701670
int ret = FAILURE;
16711671
php_stream_statbuf src_s, dest_s;
1672+
int src_stat_flags = (src_flg & STREAM_DISABLE_OPEN_BASEDIR) ? PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR : 0;
16721673

1673-
switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
1674+
switch (php_stream_stat_path_ex(src, src_stat_flags, &src_s, ctx)) {
16741675
case -1:
16751676
/* non-statable stream */
16761677
goto safe_to_copy;

0 commit comments

Comments
 (0)