Fixed bug #35499 (strtotime() does not handle whitespace around the date

string).
This commit is contained in:
Ilia Alshanetsky 2005-12-01 16:24:52 +00:00
parent f74f26f487
commit f4248e51a4
6 changed files with 25441 additions and 16936 deletions

2
NEWS
View file

@ -18,6 +18,8 @@ PHP NEWS
- Fixed many bugs in OCI8. (Tony)
- Fixed crash and leak in mysqli when using 4.1.x client libraries and
connecting to 5.x server. (Andrey)
- Fixed bug #35499 (strtotime() does not handle whitespace around the date
string). (Ilia)
- Fixed bug #35496 (Crash in mcrypt_generic()/mdecrypt_generic() without
proper init). (Ilia)
- Fixed bug #35490 (socket_sendto() unable to handle IPv6 addresses). (Tony)

File diff suppressed because it is too large Load diff

View file

@ -1379,16 +1379,32 @@ relativetext = (reltextnumber space? reltextunit)+;
/*!max:re2c */
timelib_time* timelib_strtotime(char *s, int *errors, timelib_tzdb *tzdb)
timelib_time* timelib_strtotime(char *s, int len, int *errors, timelib_tzdb *tzdb)
{
Scanner in;
int t;
char *e = s + len - 1;
while (isspace(*s) && s < e) {
s++;
}
while (isspace(*e) && e > s) {
e--;
}
if (e - s < 1) {
*errors = 1;
in.time = timelib_time_ctor();
in.time->y = in.time->d = in.time->m = in.time->h = in.time->i = in.time->s = in.time->f = in.time->z = in.time->dst = -1;
in.time->is_localtime = in.time->zone_type = 0;
return in.time;
}
e++;
memset(&in, 0, sizeof(in));
in.str = malloc(strlen(s) + YYMAXFILL);
memset(in.str, 0, strlen(s) + YYMAXFILL);
memcpy(in.str, s, strlen(s));
in.lim = in.str + strlen(s) + YYMAXFILL;
in.str = malloc((e - s) + YYMAXFILL);
memset(in.str, 0, (e - s) + YYMAXFILL);
memcpy(in.str, s, (e - s));
in.lim = in.str + (e - s) + YYMAXFILL;
in.cur = in.str;
in.time = timelib_time_ctor();
in.time->y = -1;

View file

@ -47,7 +47,7 @@ timelib_sll timelib_days_in_month(timelib_sll y, timelib_sll m);
void timelib_isoweek_from_date(timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy);
/* From parse_date.re */
timelib_time *timelib_strtotime(char *s, int *errors, timelib_tzdb *tzdb);
timelib_time *timelib_strtotime(char *s, int len, int *errors, timelib_tzdb *tzdb);
void timelib_fill_holes(timelib_time *parsed, timelib_time *now, int options);
char *timelib_timezone_id_from_abbr(const char *abbr, long gmtoffset, int isdst);
timelib_tz_lookup_table *timelib_timezone_abbreviations_list(void);

View file

@ -764,7 +764,7 @@ signed long php_parse_date(char *string, signed long *now)
int error1, error2;
signed long retval;
parsed_time = timelib_strtotime(string, &error1, DATE_TIMEZONEDB);
parsed_time = timelib_strtotime(string, strlen(string), &error1, DATE_TIMEZONEDB);
timelib_update_ts(parsed_time, NULL);
retval = timelib_date_to_int(parsed_time, &error2);
timelib_time_dtor(parsed_time);
@ -795,7 +795,7 @@ PHP_FUNCTION(strtotime)
initial_ts = emalloc(25);
snprintf(initial_ts, 24, "@%lu", preset_ts);
t = timelib_strtotime(initial_ts, &error1, DATE_TIMEZONEDB); /* we ignore the error here, as this should never fail */
t = timelib_strtotime(initial_ts, strlen(initial_ts), &error1, DATE_TIMEZONEDB); /* we ignore the error here, as this should never fail */
timelib_update_ts(t, tzi);
timelib_unixtime2local(now, t->sse, tzi);
timelib_time_dtor(t);
@ -808,7 +808,7 @@ PHP_FUNCTION(strtotime)
RETURN_FALSE;
}
t = timelib_strtotime(times, &error1, DATE_TIMEZONEDB);
t = timelib_strtotime(times, time_len, &error1, DATE_TIMEZONEDB);
timelib_fill_holes(t, now, 0);
timelib_update_ts(t, tzi);
ts = timelib_date_to_int(t, &error2);
@ -1280,7 +1280,7 @@ PHP_FUNCTION(date_create)
date_instanciate(date_ce_date, return_value TSRMLS_CC);
dateobj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", &error, DATE_TIMEZONEDB);
dateobj->time = timelib_strtotime(time_str_len ? time_str : "now", time_str_len ? time_str_len : sizeof("now") -1, &error, DATE_TIMEZONEDB);
if (timezone_object) {
php_timezone_obj *tzobj;
@ -1338,7 +1338,7 @@ PHP_FUNCTION(date_modify)
}
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
tmp_time = timelib_strtotime(modify, &error, DATE_TIMEZONEDB);
tmp_time = timelib_strtotime(modify, modify_len, &error, DATE_TIMEZONEDB);
dateobj->time->relative.y = tmp_time->relative.y;
dateobj->time->relative.m = tmp_time->relative.m;
dateobj->time->relative.d = tmp_time->relative.d;

View file

@ -0,0 +1,16 @@
--TEST--
Bug #35499 (strtotime() does not handle whitespace around the date string)
--FILE--
<?php
date_default_timezone_set("UTC");
echo date(DATE_ISO8601, strtotime("11/20/2005 8:00 AM \r\n")) . "\n";
echo date(DATE_ISO8601, strtotime(" 11/20/2005 8:00 AM \r\n")) . "\n";
var_dump(strtotime(" a "));
var_dump(strtotime(" \n "));
?>
--EXPECT--
2005-11-20T08:00:00+0000
2005-11-20T08:00:00+0000
bool(false)
bool(false)