--- embedaddon/sudo/plugins/sudoers/getdate.c 2012/02/21 16:23:02 1.1 +++ embedaddon/sudo/plugins/sudoers/getdate.c 2014/06/15 16:12:54 1.1.1.5 @@ -46,7 +46,7 @@ #ifdef HAVE_STRINGS_H # include #endif /* HAVE_STRINGS_H */ -#if TIME_WITH_SYS_TIME +#ifdef TIME_WITH_SYS_TIME # include #endif #include @@ -110,7 +110,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); @@ -122,7 +122,7 @@ typedef union { enum _MERIDIAN Meridian; } YYSTYPE; #endif /* YYSTYPE_DEFINED */ -#line 125 "y.tab.c" +#line 125 "getdate.c" #define tAGO 257 #define tDAY 258 #define tDAYZONE 259 @@ -389,7 +389,7 @@ YYSTYPE yylval; short *yyss; short *yysslim; YYSTYPE *yyvs; -int yystacksize; +unsigned int yystacksize; #line 326 "getdate.y" /* Month and day table. */ @@ -443,7 +443,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 }, */ @@ -581,19 +581,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; @@ -626,19 +621,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; @@ -654,9 +643,8 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer } DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) ? 29 : 28; - /* Checking for 2038 bogusly assumes that time_t is 32 bits. But - I'm too lazy to try to check for time_t overflow in another way. */ - if (Year < EPOCH || Year > 2038 + /* 32-bit time_t cannot represent years past 2038 */ + if (Year < EPOCH || (sizeof(time_t) == sizeof(int) && Year > 2038) || Month < 1 || Month > 12 /* Lint fluff: "conversion from long may lose accuracy" */ || Day < 1 || Day > DaysInMonth[(int)--Month]) @@ -672,37 +660,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); @@ -710,9 +701,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; @@ -720,7 +709,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; @@ -732,8 +722,7 @@ RelativeMonth(Start, RelMonth) static int -LookupWord(buff) - char *buff; +LookupWord(char *buff) { char *p; char *q; @@ -839,7 +828,7 @@ LookupWord(buff) static int -yylex() +yylex(void) { char c; char *p; @@ -894,8 +883,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); @@ -915,8 +903,7 @@ difftm (a, b) } time_t -get_date(p) - char *p; +get_date(char *p) { struct tm *tm, *gmt, gmtbuf; time_t Start; @@ -954,7 +941,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; @@ -1002,20 +988,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"); @@ -1027,8 +1011,8 @@ main(ac, av) exit(0); /* NOTREACHED */ } -#endif /* defined(TEST) */ -#line 979 "y.tab.c" +#endif /* TEST */ +#line 963 "getdate.c" /* allocate initial stack or double stack size, up to YYMAXDEPTH */ #if defined(__cplusplus) || defined(__STDC__) static int yygrowstack(void) @@ -1036,7 +1020,8 @@ static int yygrowstack(void) static int yygrowstack() #endif { - int newsize, i; + unsigned int newsize; + long sslen; short *newss; YYSTYPE *newvs; @@ -1046,28 +1031,30 @@ static int yygrowstack() return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; - i = yyssp - yyss; #ifdef SIZE_MAX #define YY_SIZE_MAX SIZE_MAX #else -#define YY_SIZE_MAX 0x7fffffff +#ifdef __STDC__ +#define YY_SIZE_MAX 0xffffffffU +#else +#define YY_SIZE_MAX (unsigned int)0xffffffff #endif - if (newsize && YY_SIZE_MAX / newsize < sizeof *newss) +#endif + if (YY_SIZE_MAX / newsize < sizeof *newss) goto bail; + sslen = yyssp - yyss; newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) : (short *)malloc(newsize * sizeof *newss); /* overflow check above */ if (newss == NULL) goto bail; yyss = newss; - yyssp = newss + i; - if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs) - goto bail; + yyssp = newss + sslen; newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) : (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */ if (newvs == NULL) goto bail; yyvs = newvs; - yyvsp = newvs + i; + yyvsp = newvs + sslen; yystacksize = newsize; yysslim = yyss + newsize - 1; return 0; @@ -1523,7 +1510,7 @@ case 41: yyval.Meridian = yyvsp[0].Meridian; } break; -#line 1474 "y.tab.c" +#line 1461 "getdate.c" } yyssp -= yym; yystate = *yyssp;