php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60456 copy() does not work consistently with stream wrappers and safe mode
Submitted: 2011-12-07 11:04 UTC Modified: 2015-08-27 14:23 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: lyricnz at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Safe Mode/open_basedir
PHP Version: 5.3.8 OS: Mac
Private report: No CVE-ID: None
 [2011-12-07 11:04 UTC] lyricnz at gmail dot com
Description:
------------
Stream wrappers which ultimately result in file operations which should be 
permitted by safe mode do not work in some circumstances. For example, a stream 
wrapper which simply stores files in sys_get_temp_dir() works fine without safe 
mode, but fails when that is enabled:

// copy 1: file to stream wrapper
$ok = copy('/tmp/source.txt', 'temp://destination.txt');

// copy 2: stream wrapper to file
$ok = copy('temp://destination.txt', '/tmp/source.txt');

// copy 3: SAME file as stream wrapper to file
$ok = copy(sys_get_temp_dir() . '/destination.txt', '/tmp/source.txt');

Under safe mode, the second copy fails with error message

   Warning: copy() [function.copy]: Unable to access temp://destination.txt in 
.../test-copy.php on line ...

This may be related to https://bugs.php.net/bug.php?id=46888


Test script:
---------------
http://drupal.org/files/test-copy.txt

Expected result:
----------------
All three file copies should succeed, since sys_get_temp_dir() returns a directory 
accessible to safe-mode.

Actual result:
--------------
Second copy fails. Third copy, which refers to the same files, succeeds.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-27 14:23 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2015-08-27 14:23 UTC] cmb@php.net
As of PHP 5.4.0 the safe mode "feature" has been removed, so this
issue is resolved.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 19:01:51 2019 UTC