--- embedaddon/sudo/plugins/sudoers/getdate.y 2013/07/22 10:46:12 1.1.1.2 +++ embedaddon/sudo/plugins/sudoers/getdate.y 2014/06/15 16:12:54 1.1.1.4 @@ -34,7 +34,7 @@ #ifdef HAVE_STRINGS_H # include #endif /* HAVE_STRINGS_H */ -#if TIME_WITH_SYS_TIME +#ifdef TIME_WITH_SYS_TIME # include #endif #include @@ -98,7 +98,7 @@ static MERIDIAN yyMeridian; static time_t yyRelMonth; static time_t yyRelSeconds; -static int yyerror(char *s); +static int yyerror(const char *s); static int yylex(void); int yyparse(void); @@ -375,7 +375,7 @@ static TABLE const OtherTable[] = { { "today", tMINUTE_UNIT, 0 }, { "now", tMINUTE_UNIT, 0 }, { "last", tUNUMBER, -1 }, - { "this", tMINUTE_UNIT, 0 }, + { "this", tUNUMBER, 0 }, { "next", tUNUMBER, 2 }, { "first", tUNUMBER, 1 }, /* { "second", tUNUMBER, 2 }, */ @@ -513,19 +513,14 @@ static TABLE const MilitaryTable[] = { /* ARGSUSED */ static int -yyerror(s) - char *s; +yyerror(const char *s) { return 0; } static time_t -ToSeconds(Hours, Minutes, Seconds, Meridian) - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; +ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) { if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) return -1; @@ -558,19 +553,13 @@ ToSeconds(Hours, Minutes, Seconds, Meridian) * A number from 0 to 99, which means a year from 1900 to 1999, or * The actual year (>=100). */ static time_t -Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) - time_t Month; - time_t Day; - time_t Year; - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; - DSTMODE DSTmode; +Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes, + time_t Seconds, MERIDIAN Meridian, DSTMODE DSTmode) { static int DaysInMonth[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + struct tm *tm; time_t tod; time_t Julian; int i; @@ -603,37 +592,40 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer return -1; Julian += tod; if (DSTmode == DSTon - || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) + || (DSTmode == DSTmaybe && (tm = localtime(&Julian)) && tm->tm_isdst)) Julian -= 60 * 60; return Julian; } static time_t -DSTcorrect(Start, Future) - time_t Start; - time_t Future; +DSTcorrect(time_t Start, time_t Future) { + struct tm *start_tm; + struct tm *future_tm; time_t StartDay; time_t FutureDay; - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; + start_tm = localtime(&Start); + future_tm = localtime(&Future); + if (!start_tm || !future_tm) + return -1; + + StartDay = (start_tm->tm_hour + 1) % 24; + FutureDay = (future_tm->tm_hour + 1) % 24; return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; } static time_t -RelativeDate(Start, DayOrdinal, DayNumber) - time_t Start; - time_t DayOrdinal; - time_t DayNumber; +RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber) { struct tm *tm; time_t now; now = Start; - tm = localtime(&now); + if (!(tm = localtime(&now))) + return -1; now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); return DSTcorrect(Start, now); @@ -641,9 +633,7 @@ RelativeDate(Start, DayOrdinal, DayNumber) static time_t -RelativeMonth(Start, RelMonth) - time_t Start; - time_t RelMonth; +RelativeMonth(time_t Start, time_t RelMonth) { struct tm *tm; time_t Month; @@ -651,7 +641,8 @@ RelativeMonth(Start, RelMonth) if (RelMonth == 0) return 0; - tm = localtime(&Start); + if (!(tm = localtime(&Start))) + return -1; Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; Year = Month / 12; Month = Month % 12 + 1; @@ -663,8 +654,7 @@ RelativeMonth(Start, RelMonth) static int -LookupWord(buff) - char *buff; +LookupWord(char *buff) { char *p; char *q; @@ -770,7 +760,7 @@ LookupWord(buff) static int -yylex() +yylex(void) { char c; char *p; @@ -825,8 +815,7 @@ yylex() /* Yield A - B, measured in seconds. */ static long -difftm (a, b) - struct tm *a, *b; +difftm(struct tm *a, struct tm *b) { int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); int by = b->tm_year + (TM_YEAR_ORIGIN - 1); @@ -846,8 +835,7 @@ difftm (a, b) } time_t -get_date(p) - char *p; +get_date(char *p) { struct tm *tm, *gmt, gmtbuf; time_t Start; @@ -885,7 +873,6 @@ get_date(p) if(tm->tm_isdst) timezone += 60; - tm = localtime(&now); yyYear = tm->tm_year + 1900; yyMonth = tm->tm_mon + 1; yyDay = tm->tm_mday; @@ -933,20 +920,18 @@ get_date(p) } -#if defined(TEST) +#ifdef TEST /* ARGSUSED */ int -main(ac, av) - int ac; - char *av[]; +main(int argc, char *argv[]) { char buff[128]; time_t d; (void)printf("Enter date, or blank line to exit.\n\t> "); (void)fflush(stdout); - while (gets(buff) && buff[0]) { + while (fgets(buff, sizeof(buff), stdin) && buff[0]) { d = get_date(buff); if (d == -1) (void)printf("Bad format - couldn't convert.\n"); @@ -958,4 +943,4 @@ main(ac, av) exit(0); /* NOTREACHED */ } -#endif /* defined(TEST) */ +#endif /* TEST */