I accidentially passed NULL to file_unmanaged_delete_recursive() and my entire install was deleted. The file rights were probably not set up quite right, but I was wondering how that could happen.

file_unmanaged_delete_recursive() and file_unmanaged_delete() both call drupal_realpath() that call the PHP function realpath().
It turns out that on *BSD systems, the PHP realpath function does not return FALSE on failure as it should. So if I do this on a mac running MAMP:

print realpath(NULL);
print realpath(FALSE);

I then get the path to the root of the drupal install... Pass NULL to the delete functions and baaad stuff happens. It has been fixed in PHP 5.3 http://php.net/manual/en/function.realpath.php but drupal 7 supports PHP 5.2.

I wrote a patch that just checks if the variable passed is not empty. It seems that the stream wrappers are not affected by the bug because they start out doing some string operations to the uri.

CommentFileSizeAuthor
#4 700160.patch999 bytesnaxoc
#2 700160.png87.28 KBjerdiggity
#1 realpath_bsd.patch732 bytesnaxoc

Comments

naxoc’s picture

Status: Active » Needs review
StatusFileSize
new732 bytes

Hmm. Patch was not uploaded. Here it is.

jerdiggity’s picture

StatusFileSize
new87.28 KB

Applied patch & ran test on file_unmanaged_delete() and file_unmanaged_delete_recursive()... All passes, 0 fails, 0 exceptions. See attached screen shot of results.
Only local images are allowed.

catch’s picture

Could we add an explicit

@todo Remove when Drupal drops support for PHP 5.2.

to the comment?

Otherwise looks like the proper fix.

naxoc’s picture

StatusFileSize
new999 bytes

Added the @todo in the comment.

catch’s picture

Status: Needs review » Reviewed & tested by the community

I don't have a BSD system to check on, but the fix looks sane and it's documented on the php.net docs themselves, so RTBC.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.