From 248c36d748368602ecb20f229af09f57d82e7818 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 18 Oct 2021 12:51:58 +0000 Subject: [PATCH] Cron: Fix malformed cron array in `wp_schedule_single_event()` when `_get_cron_array()` returns `false`. In `wp_schedule_single_event()`, the cron info array is retrieved via a call to `_get_cron_array()` and straight away cast to an array. But as the documentation for that function (correctly) states, the return type of that function is `array|false`, where `false` is returned for a site where no cron jobs have been scheduled (yet). In the case that `_get_cron_array()` would return `false`, this would now unintentionally create an array with a single entry with key `0` and as the value `false`. This is a bug. Fixed now by adding validation to the output of `_get_cron_array()` and initializing `$crons` to an empty array if `false` was returned. Tests added first to prove the bug (a) was introduced in #44818 [44917] and (b) is now fixed. Follow-up to [44917]. Props jrf, peterwilsoncc. Fixes #53950. Built from https://develop.svn.wordpress.org/trunk@51916 git-svn-id: http://core.svn.wordpress.org/trunk@51509 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/cron.php | 6 +++++- wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wp-includes/cron.php b/wp-includes/cron.php index f4810e55a3..41efeebc44 100644 --- a/wp-includes/cron.php +++ b/wp-includes/cron.php @@ -118,7 +118,11 @@ function wp_schedule_single_event( $timestamp, $hook, $args = array(), $wp_error * current time) all events scheduled within the next ten minutes * are considered duplicates. */ - $crons = (array) _get_cron_array(); + $crons = _get_cron_array(); + if ( ! is_array( $crons ) ) { + $crons = array(); + } + $key = md5( serialize( $event->args ) ); $duplicate = false; diff --git a/wp-includes/version.php b/wp-includes/version.php index a7b986719d..47b53ae64d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-51915'; +$wp_version = '5.9-alpha-51916'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.