1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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
This commit is contained in:
Ilija Tovilo
2023-04-28 18:04:47 +02:00
parent f0149c5c0b
commit 8bf2d587d7
3 changed files with 34 additions and 1 deletions

4
NEWS
View File

@@ -8,6 +8,10 @@ PHP NEWS
- PGSQL:
. Fixed parameter parsing of pg_lo_export(). (kocsismate)
- Standard:
. Fixed bug GH-11138 (move_uploaded_file() emits open_basedir warning for
source file). (ilutov)
11 May 2023, PHP 8.1.19
- Core:

28
Zend/tests/gh11138.phpt Normal file
View File

@@ -0,0 +1,28 @@
--TEST--
move_uploaded_file() emits open_basedir warning for source file
--POST_RAW--
Content-type: multipart/form-data, boundary=AaB03x
--AaB03x
content-disposition: form-data; name="file"; filename="file.txt"
Content-Type: text/plain
foo
--AaB03x--
--FILE--
<?php
ini_set('open_basedir', __DIR__);
$destination = __DIR__ . '/gh11138.tmp';
var_dump(move_uploaded_file($_FILES['file']['tmp_name'], $destination));
echo file_get_contents($destination), "\n";
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh11138.tmp');
?>
--EXPECT--
bool(true)
foo

View File

@@ -1669,8 +1669,9 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
php_stream *srcstream = NULL, *deststream = NULL;
int ret = FAILURE;
php_stream_statbuf src_s, dest_s;
int src_stat_flags = (src_flg & STREAM_DISABLE_OPEN_BASEDIR) ? PHP_STREAM_URL_STAT_IGNORE_OPEN_BASEDIR : 0;
switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
switch (php_stream_stat_path_ex(src, src_stat_flags, &src_s, ctx)) {
case -1:
/* non-statable stream */
goto safe_to_copy;