Opened 5 months ago
Last modified 5 months ago
#23196 new defect (bug)
mkdir not recursive (in wp-includes/functions.php)
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Filesystem | Version: | |
| Severity: | normal | Keywords: | |
| Cc: |
Description
This January, Wordpress tried to create a directory and a subdirectory in "uploads": "2013" and inside it "01".
mkdir($target) was used to create these two directories, but since the $recursive option (3rd argument) was not set, this operation failed.
I have just checked this path and it does exist, hence I suspect this procedure is being done somewhere else (and succeeding).
Still, this is a problem since:
- It is showing up in our error logging system.
- It is very easy to fix.
- It potentially fixes more problems than it seems.
The solution is to change this line:
1306: if ( @mkdir( $target ) ) {
To the following:
1306: if ( @mkdir( $target, 0777, true ) ) {
On a sidenote, PHP's default directory creation mode is 0777 (so the above code is best for compatibility), but as you may know, it is not good in terms of security, so you may want to look for a more secure fix (eg, lowering the mode if it doesn't cause problems).
Change History (6)
comment:1
SergeyBiryukov
— 5 months ago
- Component changed from General to Filesystem
- Keywords has-patch removed
comment:3
in reply to:
↑ 2
uuf6429
— 5 months ago
Replying to dd32:
Although a error may be logged in this case, the function, wp_mkdir_p does attempt to recursively create the directories, but doesn't use the recursive option (since it was written when we still supported PHP4).
Well then, go fix it. :-)
comment:4
follow-up:
↓ 5
dd32
— 5 months ago
If the folder didn't get created for you, chances are your uploads folder doesn't allow folder creation at present, and using the recursive option still wouldn't have fixed it.
Well then, go fix it. :-)
Feel free to submit a patch.
comment:5
in reply to:
↑ 4
;
follow-up:
↓ 6
uuf6429
— 5 months ago
Replying to dd32:
If the folder didn't get created for you, chances are your uploads folder doesn't allow folder creation at present, and using the recursive option still wouldn't have fixed it.
If you read my issue above again, I said at some point in time the folder was created anyway.
And in case that wasn't enough, I know for sure Wordpress does have permission to create folders on the host in question.
I don't track when/who creates folders on my server, I only log issues such as this one, including it's time, file/line of occurrence and the variables in scope. From all this info, it seems the only logical issue is what I mentioned above.
Feel free to submit a patch.
But then, we bypass the need of Trac, and we don't want that, do we?
comment:6
in reply to:
↑ 5
rmccue
— 5 months ago
Replying to uuf6429:
But then, we bypass the need of Trac, and we don't want that, do we?
Actually, that's kinda the main point of Trac: you can write a patch, and attach it to this ticket right here (via the "Attach file" button just below the description). :)
Although a error may be logged in this case, the function, wp_mkdir_p does attempt to recursively create the directories, but doesn't use the recursive option (since it was written when we still supported PHP4).