From bf09fe506620678fb82c3b872309edda0ed8ce61 Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 18 Sep 2024 22:35:35 +0000 Subject: [PATCH] Date/Time, PHP Compat: Prevent type errors using GMT offset option. Prevents a potential type errors when making use of the `gmt_offset` option by casting the value to a float prior to performing calculations with the value. This mainly accounts for incorrect storage of values, such as an empty string or city name. Follow up to [58923]. Props chaion07, hellofromtonya, kirasong, mhshohel, mukesh27, nicolefurlan, nihar007, nurielmeni, oglekler, peterwilsoncc, prionkor, rajinsharwar, rarst, rleeson, sabernhardt, SergeyBiryukov, swissspidy, toastercookie, verygoode. Fixes #56358, #58986, #60629. git-svn-id: https://develop.svn.wordpress.org/trunk@59064 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/update-core.php | 2 +- src/wp-includes/bookmark-template.php | 2 +- .../rest-api/endpoints/class-wp-rest-posts-controller.php | 2 +- src/wp-mail.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/update-core.php b/src/wp-admin/update-core.php index 3e48bae0daa04..b41f7285dcea9 100644 --- a/src/wp-admin/update-core.php +++ b/src/wp-admin/update-core.php @@ -1096,7 +1096,7 @@ function do_undismiss_core_update() { $current = get_site_transient( 'update_core' ); if ( $current && isset( $current->last_checked ) ) { - $last_update_check = $current->last_checked + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; + $last_update_check = $current->last_checked + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); } echo '

'; diff --git a/src/wp-includes/bookmark-template.php b/src/wp-includes/bookmark-template.php index d5878887d9895..af48fbfdca7cf 100644 --- a/src/wp-includes/bookmark-template.php +++ b/src/wp-includes/bookmark-template.php @@ -90,7 +90,7 @@ function _walk_bookmarks( $bookmarks, $args = '' ) { __( 'Last updated: %s' ), gmdate( get_option( 'links_updated_date_format' ), - $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) + $bookmark->link_updated_f + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) ); $title .= ')'; diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 8aec375bc8bb8..d1938872edd8d 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1816,7 +1816,7 @@ public function prepare_item_for_response( $item, $request ) { * with the site's timezone offset applied. */ if ( '0000-00-00 00:00:00' === $post->post_modified_gmt ) { - $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); + $post_modified_gmt = gmdate( 'Y-m-d H:i:s', strtotime( $post->post_modified ) - (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); } else { $post_modified_gmt = $post->post_modified_gmt; } diff --git a/src/wp-mail.php b/src/wp-mail.php index c405f6969e355..7b18dd4ad1494 100644 --- a/src/wp-mail.php +++ b/src/wp-mail.php @@ -44,7 +44,7 @@ set_transient( 'mailserver_last_checked', true, WP_MAIL_INTERVAL ); -$time_difference = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS; +$time_difference = (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); $phone_delim = '::';