@@ -14507,6 +14507,23 @@ int GetTimeString(byte* date, int format, char* buf, int len)
1450714507}
1450814508#endif /* OPENSSL_ALL || WOLFSSL_MYSQL_COMPATIBLE || WOLFSSL_NGINX || WOLFSSL_HAPROXY */
1450914509
14510+ /* Check time struct for valid values. Returns 0 for success */
14511+ static int ValidateGmtime(struct tm* inTime)
14512+ {
14513+ int ret = 1;
14514+ if ((inTime != NULL) &&
14515+ (inTime->tm_sec >= 0) && (inTime->tm_sec <= 61) &&
14516+ (inTime->tm_min >= 0) && (inTime->tm_min <= 59) &&
14517+ (inTime->tm_hour >= 0) && (inTime->tm_hour <= 23) &&
14518+ (inTime->tm_mday >= 1) && (inTime->tm_mday <= 31) &&
14519+ (inTime->tm_mon >= 0) && (inTime->tm_mon <= 11) &&
14520+ (inTime->tm_wday >= 0) && (inTime->tm_wday <= 6) &&
14521+ (inTime->tm_yday >= 0) && (inTime->tm_yday <= 365)) {
14522+ ret = 0;
14523+ }
14524+
14525+ return ret;
14526+ }
1451014527
1451114528#if !defined(NO_ASN_TIME) && !defined(USER_TIME) && \
1451214529 !defined(TIME_OVERRIDES) && (defined(OPENSSL_EXTRA) || defined(HAVE_PKCS7))
@@ -14583,7 +14600,7 @@ int GetFormattedTime(void* currTime, byte* buf, word32 len)
1458314600 return BAD_FUNC_ARG;
1458414601
1458514602 ts = (struct tm *)XGMTIME((time_t*)currTime, tmpTime);
14586- if (ts == NULL ) {
14603+ if (ValidateGmtime(ts) ) {
1458714604 WOLFSSL_MSG("failed to get time data.");
1458814605 return ASN_TIME_E;
1458914606 }
@@ -14750,7 +14767,7 @@ int wc_ValidateDate(const byte* date, byte format, int dateType)
1475014767 ltime -= (time_t)timeDiff;
1475114768 localTime = XGMTIME(<ime, tmpTime);
1475214769
14753- if (localTime == NULL ) {
14770+ if (ValidateGmtime( localTime) ) {
1475414771 WOLFSSL_MSG("XGMTIME failed");
1475514772 return 0;
1475614773 }
@@ -28121,7 +28138,7 @@ static int SetValidity(byte* output, int daysValid)
2812128138 /* subtract 1 day of seconds for more compliance */
2812228139 then = now - 86400;
2812328140 expandedTime = XGMTIME(&then, tmpTime);
28124- if (expandedTime == NULL ) {
28141+ if (ValidateGmtime( expandedTime) ) {
2812528142 WOLFSSL_MSG("XGMTIME failed");
2812628143 return 0; /* error */
2812728144 }
@@ -28140,7 +28157,7 @@ static int SetValidity(byte* output, int daysValid)
2814028157 /* add daysValid of seconds */
2814128158 then = now + (daysValid * (time_t)86400);
2814228159 expandedTime = XGMTIME(&then, tmpTime);
28143- if (expandedTime == NULL ) {
28160+ if (ValidateGmtime( expandedTime) ) {
2814428161 WOLFSSL_MSG("XGMTIME failed");
2814528162 return 0; /* error */
2814628163 }
@@ -28189,7 +28206,7 @@ static int SetValidity(byte* before, byte* after, int daysValid)
2818928206 /* subtract 1 day of seconds for more compliance */
2819028207 then = now - 86400;
2819128208 expandedTime = XGMTIME(&then, tmpTime);
28192- if (expandedTime == NULL ) {
28209+ if (ValidateGmtime( expandedTime) ) {
2819328210 WOLFSSL_MSG("XGMTIME failed");
2819428211 ret = DATE_E;
2819528212 }
@@ -28205,7 +28222,7 @@ static int SetValidity(byte* before, byte* after, int daysValid)
2820528222 /* add daysValid of seconds */
2820628223 then = now + (daysValid * (time_t)86400);
2820728224 expandedTime = XGMTIME(&then, tmpTime);
28208- if (expandedTime == NULL ) {
28225+ if (ValidateGmtime( expandedTime) ) {
2820928226 WOLFSSL_MSG("XGMTIME failed");
2821028227 ret = DATE_E;
2821128228 }
0 commit comments