Skip to content

Commit a38c852

Browse files
authored
Guard fclose() against false stream in supercache-only mode (#1053)
* Guard fclose() against false stream in supercache-only mode In supercache-only mode $fr is false (the wp-cache file is never opened). When the supercache temp file fails to open, the error branches called @fclose( $fr ) = @fclose( false ). On PHP 8+ that is a TypeError, which @ does not suppress, so the request fatals. Only call fclose() when the stream is open. Fixes #1016. * Silence AlternativeFunctions warning on guarded fclose calls phpcs-changed flags the now-modified fclose() lines under WordPress.WP.AlternativeFunctions; match the file's existing inline-ignore convention for direct filesystem calls.
1 parent ed5d373 commit a38c852

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

wp-cache-phase2.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,9 @@ function wp_cache_get_ob( &$buffer ) {
24182418
if ( ! $fr2 ) {
24192419
wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ), 1 );
24202420
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) );
2421-
@fclose( $fr );
2421+
if ( $fr ) {
2422+
fclose( $fr ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
2423+
}
24222424
@unlink( $tmp_wpcache_filename );
24232425
wp_cache_writers_exit();
24242426
return wp_cache_maybe_dynamic( $buffer );
@@ -2430,7 +2432,9 @@ function wp_cache_get_ob( &$buffer ) {
24302432
if ( ! $gz ) {
24312433
wp_cache_debug( 'Error. Supercache could not write to ' . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz', 1 );
24322434
wp_cache_add_to_buffer( $buffer, "File not cached! Super Cache Couldn't write to: " . str_replace( ABSPATH, '', $tmp_cache_filename ) . '.gz' );
2433-
@fclose( $fr );
2435+
if ( $fr ) {
2436+
fclose( $fr ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose
2437+
}
24342438
@unlink( $tmp_wpcache_filename );
24352439
@fclose( $fr2 );
24362440
@unlink( $tmp_cache_filename );

0 commit comments

Comments
 (0)