Skip to content

Propagate STREAM_DISABLE_OPEN_BASEDIR src flag to php_stream_stat_path_ex #11156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 28 additions & 0 deletions Zend/tests/gh11138.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
move_uploaded_file() and open_basedir
--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
3 changes: 2 additions & 1 deletion ext/standard/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down