Loading...
--- Libc/Libc-391/stdtime/getdate.c
+++ Libc/Libc-594.1.4/stdtime/getdate.c
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
@@ -48,7 +49,7 @@
#define TM_YEAR_SET 0x04
#define UNDEFINED -1
-static struct tm tmundef = {
+static const struct tm tmundef = {
UNDEFINED,
UNDEFINED,
UNDEFINED,
@@ -69,10 +70,11 @@
struct tm *
getdate(const char *str)
{
- static struct tm tm, *now, *result = NULL;
+ static struct tm tm;
+ struct tm *now, *result = NULL;
time_t t;
FILE *fp;
- int bufsiz, offset, len, dateset, timeset, saveerrno, wday_set;
+ int bufsiz, offset, len, dateset, timeset, saveerrno, wday_set, save_mon;
char *buf;
struct stat st;
char *file = getenv(DATEMSK);
@@ -218,7 +220,7 @@
case TM_YEAR_SET:
case TM_YEAR_SET | TM_MON_SET:
if(!(dateset & TM_MON_SET))
- tm.tm_mon = 1;
+ tm.tm_mon = 0;
tm.tm_mday = 1;
break;
@@ -232,10 +234,13 @@
tm.tm_wday = now->tm_wday;
tm.tm_gmtoff = now->tm_gmtoff; /* XXX: can't grok timezones */
tm.tm_isdst = -1;
-
+ save_mon = tm.tm_mon;
if(mktime(&tm) == (time_t)-1) {
getdate_err = INVALID_DATE;
break;
+ } else if ((dateset & TM_MON_SET) && (tm.tm_mon != save_mon)) { /* Did mktime fixup an overflow date? */
+ getdate_err = INVALID_DATE;
+ break;
}
if(wday_set != UNDEFINED) {
int delta = wday_set - tm.tm_wday;
@@ -252,6 +257,7 @@
}
}
result = &tm;
+ break;
}
} while(0);