#23289 closed defect (bug) (fixed)
wp_protect_special_option rejects things it shouldn't
| Reported by: | agarden | Owned by: | nacin |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.6 |
| Component: | General | Version: | 2.2 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
If wp_protect_special_option is called with $option == 0 it will die. I have a client for whom this took down their entire WordPress install. Now, I assume that some plugin or some such should not have been passing zero as an option name, so that's another bug. But a buggy plugin should not be able to take down an entire install so carelessly.
Fix is trivial. Have in_array use strict checking. Patch is attached.
Attachments (2)
Change History (10)
#1
@
14 years ago
- Milestone Awaiting Review → 3.6
- Version trunk → 2.2
Related: #2268
Confirmed that in_array( 0, array( 'alloptions', 'notoptions' ) ) returns true.
#2
follow-up:
↓ 3
@
14 years ago
PHP, this earns you another WTF?
Compare
var_dump( in_array( 0, array( '1', 'a2' ) ) ); // bool(true)
to
var_dump( in_array( 0, array( '1', '2a' ) ) ); // bool(false)
I'm a little bit speechless right now...
#3
in reply to: ↑ 2
@
14 years ago
- Keywords commit added
Replying to TobiasBg:
PHP, this earns you another WTF?
Makes full sense given that it's a non-strict comparison. When converting strings to integers, it takes as many digits as possible before a non-digit and turns that into an integer. In this case, 2a becomes 2, but there are no digits at the start of a2, so that becomes 0.
Patch looks good, +1.
#4
@
14 years ago
Ok, I'm no longer speechless. I guess that does make sense, given that
var_dump( 0 == 'a2' );
also gives true.
Initially, I was expecting (or hoping?) for strict comparison to be the default in in_array, but that would be inconsistent with other functions. So, yeah, it does make sense.
#5
@
14 years ago
Best I can tell, this would only affect delete_option(). The other methods — get, update, and add — all trim( $option ) then check if $option is empty, and if so, return false. trim() would convert 0 to '0' but this is still empty.
#6
@
14 years ago
In 1222/tests:
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Patch