-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Handle bad interval for cron schedule #10619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
westonruter
wants to merge
12
commits into
WordPress:trunk
Choose a base branch
from
westonruter:trac-64404
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
101f58f
Handle bad interval for cron schedule
westonruter b39b67d
Fix logic inversion
westonruter d023b9a
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 3bba3b9
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter 76f3901
Revert initial casting to int
westonruter 0184a4d
Use is_numeric() instead of is_int()
westonruter 063c21e
Add recurrence to the error message
westonruter 662315d
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develo…
westonruter cda5935
Fix failing test
westonruter c6efb67
Add interval check to wp_schedule_event() and differentiate errors in…
westonruter d1c3ba6
Merge branch 'trunk' into trac-64404
westonruter 0fae040
Add additional test cases
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -316,6 +316,17 @@ function wp_schedule_event( $timestamp, $recurrence, $hook, $args = array(), $wp | |||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| if ( ! is_numeric( $event->interval ) || $event->interval <= 0 ) { | ||||||
| if ( $wp_error ) { | ||||||
| return new WP_Error( | ||||||
| 'invalid_interval', | ||||||
| __( 'Event schedule has invalid interval.' ) | ||||||
| ); | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| $key = md5( serialize( $event->args ) ); | ||||||
|
|
||||||
| $crons = _get_cron_array(); | ||||||
|
|
@@ -444,12 +455,19 @@ function wp_reschedule_event( $timestamp, $recurrence, $hook, $args = array(), $ | |||||
| } | ||||||
|
|
||||||
| // Now we assume something is wrong and fail to schedule. | ||||||
| if ( 0 === $interval ) { | ||||||
| if ( ! is_numeric( $interval ) || $interval <= 0 ) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same suggestion here:
Suggested change
|
||||||
| if ( $wp_error ) { | ||||||
| return new WP_Error( | ||||||
| 'invalid_schedule', | ||||||
| __( 'Event schedule does not exist.' ) | ||||||
| ); | ||||||
| if ( ! isset( $schedules[ $recurrence ] ) ) { | ||||||
| return new WP_Error( | ||||||
| 'invalid_schedule', | ||||||
| __( 'Event schedule does not exist.' ) | ||||||
| ); | ||||||
| } else { | ||||||
| return new WP_Error( | ||||||
| 'invalid_interval', | ||||||
| __( 'Event schedule has invalid interval.' ) | ||||||
| ); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
|
|
||||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fractional floats between 0 and 1 (like
0.5,0.1,0.99) pass this validation becauseis_numeric(0.5)istrueand0.5 > 0. But PHP's%operator casts floats to int, so0.5becomes0and the modulo inwp_reschedule_event()still throwsDivisionByZeroError.Casting to
(int)here catches these values at validation time, the same way the arithmetic would truncate them:I verified it locally without the cast,
wp_schedule_event( time(), 'half_second_schedule', ... )succeeds andwp_reschedule_event()crashes. With the cast, both returninvalid_intervalcorrectly.