Fix cache directory permissions and PHP 8+ TypeError on fopen failure#7
Open
toineenzo wants to merge 1 commit into
Open
Fix cache directory permissions and PHP 8+ TypeError on fopen failure#7toineenzo wants to merge 1 commit into
toineenzo wants to merge 1 commit into
Conversation
- mkdir() was using mode 0600 which prevents PHP from traversing the directory it just created, breaking subsequent file_exists()/fopen() calls inside it. Use 0755 so the cache directory is actually usable. - ozh_ycache_shutdown() called fwrite()/fclose() on the result of fopen() without checking for failure. Since PHP 8.0 these functions require a resource argument and throw TypeError when given false (e.g. when the cache directory is missing or unwritable). Guard the write with an explicit check. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
|
Thanks. I think this PR fixes two problems that don't exist :
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two small, backwards-compatible fixes in
plugin.php:1.
mkdir()mode0600->0755On activation, the plugin creates a
cache/directory with mode0600. That mode (rw-for owner only, no execute bit) prevents PHP from traversing the directory it just created, so subsequentfile_exists(),filemtime(), andfopen()calls against files insidecache/silently fail. Switching to0755makes the directory actually usable.2. Guard
fwrite()/fclose()againstfopen()failureozh_ycache_shutdown()did:If
fopen()fails (cache dir missing, unwritable, full disk, etc.), it returnsfalse. Since PHP 8.0,fwrite()andfclose()require a resource and throwTypeErrorwhen givenfalse, which would crash the request. Added an explicitif ( $fp !== false )check around the writes. The buffered output is still echoed to the browser either way, so a write failure now degrades gracefully instead of fatally.No version bump, no behavior change on the happy path.
Test plan
cache/is created and writable by PHP+) twice, confirm second hit serves from cache (<!-- Cached ... -->marker)chmod 000 cache/and visit a stat page; confirm no fatalTypeError, page still renders