Opened 12 years ago
Closed 12 years ago
#29801 closed defect (bug) (fixed)
Improper value sanitization in WP_Date_Query::build_value() can lead to incorrect results
| Reported by: | boonebgorges | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.1 |
| Component: | Date/Time | Version: | |
| Severity: | minor | Keywords: | |
| Cc: | Focuses: |
Description
WP_Date_Query::build_value() sanitizes the $value param for two purposes: (1) for safe use in SQL queries, and (2) to make sure that the values provided make sense with the $compare operator. However, the reliance on intval() means that the following cases arise:
- With compare
INandNOT IN, values like'foo'turn into(0)while'foo1'turns into(1) - With compare
BETWEENandNOT BETWEEN, a singleton array as the$valuewill be sanitized down to1, leading to clauses likeBETWEEN 1 AND 1
In each of these cases, the query might end up returning unexpected results. I suggest returning false out of build_query() when an invalid value is passed. The attached patch does this using is_numeric().
A related issue that I've also addressed in the patch: for BETWEEN and NOT BETWEEN, passing a two-membered array like array( 2 => 5, 3 => 6 ) would result in the query failing, because the parser is expected array keys 0 and 1. I suggest that in cases where two numeric values are passed, we use them, regardless of the keys.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Commit message seems to have missed this. Fixed in r29797.