Download & Extend

drupal_realpath does not always work as expected

Project:Drupal core
Version:7.x-dev
Component:file system
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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.

Comments

#1

Status:active» needs review

Hmm. Patch was not uploaded. Here it is.

AttachmentSizeStatusTest resultOperations
realpath_bsd.patch732 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch realpath_bsd_0.patch.View details

#2

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.

AttachmentSizeStatusTest resultOperations
700160.png87.28 KBIgnored: Check issue status.NoneNone

#3

Could we add an explicit


@todo Remove when Drupal drops support for PHP 5.2.

to the comment?

Otherwise looks like the proper fix.

#4

Added the @todo in the comment.

AttachmentSizeStatusTest resultOperations
700160.patch999 bytesIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 700160.patch.View details

#5

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.

#6

Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#7

Status:fixed» closed (fixed)

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

nobody click here