From: Alejandro Colomar Date: Tue, 18 Feb 2025 11:16:48 +0000 (+0100) Subject: lib/getdate.y: Don't parse relative dates, such as 'yesterday' X-Git-Tag: 4.18.0-rc1~105 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a0bed09fb5167df6252433f87599f2a23bce43f5;p=thirdparty%2Fshadow.git lib/getdate.y: Don't parse relative dates, such as 'yesterday' Signed-off-by: Alejandro Colomar --- diff --git a/lib/getdate.y b/lib/getdate.y index f294fcba5..649fb21d1 100644 --- a/lib/getdate.y +++ b/lib/getdate.y @@ -116,13 +116,9 @@ static int yyDayOrdinal; static int yyDayNumber; static int yyHaveDate; static int yyHaveDay; -static int yyHaveRel; static int yyDay; static int yyMonth; static int yyYear; -static int yyRelDay; -static int yyRelMonth; -static int yyRelYear; %} @@ -130,13 +126,13 @@ static int yyRelYear; int Number; } -%token tAGO tDAY tDAY_UNIT tID -%token tMONTH tMONTH_UNIT -%token tSNUMBER tUNUMBER tYEAR_UNIT +%token tDAY tID +%token tMONTH +%token tSNUMBER tUNUMBER -%type tDAY tDAY_UNIT -%type tMONTH tMONTH_UNIT -%type tSNUMBER tUNUMBER tYEAR_UNIT +%type tDAY +%type tMONTH +%type tSNUMBER tUNUMBER %% @@ -150,9 +146,6 @@ item : date { | day { yyHaveDay++; } - | rel { - yyHaveRel++; - } | number ; @@ -224,43 +217,6 @@ date : tUNUMBER '/' tUNUMBER { } ; -rel : relunit tAGO { - yyRelDay = -yyRelDay; - yyRelMonth = -yyRelMonth; - yyRelYear = -yyRelYear; - } - | relunit - ; - -relunit : tUNUMBER tYEAR_UNIT { - yyRelYear += $1 * $2; - } - | tSNUMBER tYEAR_UNIT { - yyRelYear += $1 * $2; - } - | tYEAR_UNIT { - yyRelYear += $1; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - | tUNUMBER tDAY_UNIT { - yyRelDay += $1 * $2; - } - | tSNUMBER tDAY_UNIT { - yyRelDay += $1 * $2; - } - | tDAY_UNIT { - yyRelDay += $1; - } - ; - number : tUNUMBER { yyHaveDate++; @@ -301,41 +257,6 @@ static TABLE const MonthDayTable[] = { { NULL, 0, 0 } }; -/* Time units table. */ -static TABLE const UnitsTable[] = { - { "year", tYEAR_UNIT, 1 }, - { "month", tMONTH_UNIT, 1 }, - { "fortnight", tDAY_UNIT, 14 }, - { "week", tDAY_UNIT, 7 }, - { "day", tDAY_UNIT, 1 }, - { NULL, 0, 0 } -}; - -/* Assorted relative-time words. */ -static TABLE const OtherTable[] = { - { "tomorrow", tDAY_UNIT, 1 }, - { "yesterday", tDAY_UNIT, -1 }, - { "today", tDAY_UNIT, 0 }, - { "now", tDAY_UNIT, 0 }, - { "last", tUNUMBER, -1 }, - { "this", tDAY_UNIT, 0 }, - { "next", tUNUMBER, 2 }, - { "first", tUNUMBER, 1 }, -/* { "second", tUNUMBER, 2 }, */ - { "third", tUNUMBER, 3 }, - { "fourth", tUNUMBER, 4 }, - { "fifth", tUNUMBER, 5 }, - { "sixth", tUNUMBER, 6 }, - { "seventh", tUNUMBER, 7 }, - { "eighth", tUNUMBER, 8 }, - { "ninth", tUNUMBER, 9 }, - { "tenth", tUNUMBER, 10 }, - { "eleventh", tUNUMBER, 11 }, - { "twelfth", tUNUMBER, 12 }, - { "ago", tAGO, 1 }, - { NULL, 0, 0 } -}; - @@ -363,7 +284,6 @@ static int LookupWord (char *buff) { register char *p; register const TABLE *tp; - int i; bool abbrev; /* Make it lowercase. */ @@ -399,34 +319,6 @@ static int LookupWord (char *buff) } } - for (tp = UnitsTable; tp->name; tp++) - if (streq(buff, tp->name)) - { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - i = strlen (buff) - 1; - if (buff[i] == 's') - { - stpcpy(&buff[i], ""); - for (tp = UnitsTable; tp->name; tp++) - if (streq(buff, tp->name)) - { - yylval.Number = tp->value; - return tp->type; - } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ - } - - for (tp = OtherTable; tp->name; tp++) - if (streq(buff, tp->name)) - { - yylval.Number = tp->value; - return tp->type; - } - return tID; } @@ -500,20 +392,16 @@ time_t get_date (const char *p, const time_t *now) yyYear = tmp->tm_year + TM_YEAR_ORIGIN; yyMonth = tmp->tm_mon + 1; yyDay = tmp->tm_mday; - yyRelDay = 0; - yyRelMonth = 0; - yyRelYear = 0; yyHaveDate = 0; yyHaveDay = 0; - yyHaveRel = 0; if (yyparse () || yyHaveDate > 1 || yyHaveDay > 1) return -1; - tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN + yyRelYear; - tm.tm_mon = yyMonth - 1 + yyRelMonth; - tm.tm_mday = yyDay + yyRelDay; + tm.tm_year = ToYear (yyYear) - TM_YEAR_ORIGIN; + tm.tm_mon = yyMonth - 1; + tm.tm_mday = yyDay; tm.tm_hour = tm.tm_min = tm.tm_sec = 0; tm.tm_isdst = 0;