From f849e4312073f8820784ed0c3621727f703e6cf5 Mon Sep 17 00:00:00 2001 From: =?utf-8?q?Ond=C5=99ej=20Va=C5=A1=C3=ADk?= Date: Fri, 27 Jun 2008 18:05:26 +0200 Subject: [PATCH] *lib/getdate.y: No longer allow invalid timezones(UTC-12 to UTC+14 allowed), consider TZ string -14 to +14 as hours(and add minutes if no minutes are specified) Signed-off-by: Ondřej Vašík --- lib/getdate.y | 31 +++++++++++++++++++++++-------- 1 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/getdate.y b/lib/getdate.y index e4f2598..f33c0a4 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -205,7 +205,7 @@ typedef struct union YYSTYPE; static int yylex (union YYSTYPE *, parser_control *); static int yyerror (parser_control const *, char const *); -static long int time_zone_hhmm (textint, long int); +static long int time_zone_hhmm (parser_control *, textint, long int); /* Extract into *PC any date and time info from a string of digits of the form e.g., YYYYMMDD, YYMMDD, HHMM, HH (and sometimes YYY, @@ -357,7 +357,7 @@ time: extract_hhmmss (pc, $1.value, $3.value, 0, 0); pc->meridian = MER24; pc->zones_seen++; - pc->time_zone = time_zone_hhmm ($4, $5); + pc->time_zone = time_zone_hhmm (pc, $4, $5); } | tUNUMBER ':' tUNUMBER ':' unsigned_seconds o_merid { @@ -369,7 +369,7 @@ time: extract_hhmmss (pc, $1.value, $3.value, $5.tv_sec, $5.tv_nsec); pc->meridian = MER24; pc->zones_seen++; - pc->time_zone = time_zone_hhmm ($6, $7); + pc->time_zone = time_zone_hhmm (pc, $6, $7); } ; @@ -393,7 +393,7 @@ zone: { pc->time_zone = $1; extract_relative_time (pc, $2, 1); } | tZONE tSNUMBER o_colon_minutes - { pc->time_zone = $1 + time_zone_hhmm ($2, $3); } + { pc->time_zone = $1 + time_zone_hhmm (pc, $2, $3); } | tDAYZONE { pc->time_zone = $1 + 60; } | tZONE tDST @@ -794,15 +794,30 @@ static table const military_table[] = /* Convert a time zone expressed as HH:MM into an integer count of minutes. If MM is negative, then S is of the form HHMM and needs - to be picked apart; otherwise, S is of the form HH. */ + to be picked apart; otherwise, S is of the form HH. Check for + possibly invalid time zones formats */ static long int -time_zone_hhmm (textint s, long int mm) +time_zone_hhmm (parser_control *pc, textint s, long int mm) { + long int returnvalue; + /* if s.value is lower than 15, add 00 minutes if mm not specified + as common time zones ranges between UTC-1200 and UTC+1400 */ + if ((abs(s.value) < 15) && (mm < 0)) + s.value *= 100; + if (mm < 0) - return (s.value / 100) * 60 + s.value % 100; + returnvalue = (s.value / 100) * 60 + s.value % 100; else - return s.value * 60 + (s.negative ? -mm : mm); + returnvalue = s.value * 60 + (s.negative ? -mm : mm); + + /* check if the return value is in real timezone range, + otherwise increment pc->zones_seen to cause time format + error, allow UTC-1200 to UTC+1400 */ + if ((returnvalue > 840) || (returnvalue < -720)) + pc->zones_seen++; + + return returnvalue; } static int -- 1.5.2.2