Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions libclamav/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,28 +1748,32 @@ X509 *cl_load_cert(const char *certpath)

struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
{
struct tm *t;
char *str;
const char *fmt = NULL;
struct tm *ret = NULL;
struct tm *t = NULL;
char *str = NULL;
const char *data, *fmt = NULL;
time_t localt;
#ifdef _WIN32
struct tm localtm, *ltm;
#else
struct tm localtm;
#endif

if (!(timeobj) || !(timeobj->data))
return NULL;
if (timeobj == NULL || (data = ASN1_STRING_get0_data(timeobj)) == NULL)
goto done;

str = CLI_STRNDUP(data, ASN1_STRING_length(timeobj));
if (NULL == str)
goto done;

str = (char *)(timeobj->data);
if (strlen(str) < 12)
return NULL;
goto done;

t = (struct tm *)calloc(1, sizeof(struct tm));
if (!(t))
return NULL;
goto done;

if (timeobj->type == V_ASN1_UTCTIME) {
if (ASN1_STRING_type(timeobj) == V_ASN1_UTCTIME) {
/* two digit year */
fmt = "%y%m%d%H%M%S";
if (str[3] == '0') {
Expand All @@ -1778,7 +1782,7 @@ struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
} else {
str[3]--;
}
} else if (timeobj->type == V_ASN1_GENERALIZEDTIME) {
} else if (ASN1_STRING_type(timeobj) == V_ASN1_GENERALIZEDTIME) {
/* four digit year */
fmt = "%Y%m%d%H%M%S";
if (str[5] == '0') {
Expand All @@ -1789,15 +1793,11 @@ struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
}
}

if (!(fmt)) {
free(t);
return NULL;
}
if (!(fmt))
goto done;

if (!strptime(str, fmt, t)) {
free(t);
return NULL;
}
if (!strptime(str, fmt, t))
goto done;

/* Convert to local time */
localt = time(NULL);
Expand All @@ -1808,7 +1808,15 @@ struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
localtime_r(&localt, &localtm);
#endif
t->tm_isdst = localtm.tm_isdst;
return t;

ret = t;
t = NULL;

done:
free(t);
free(str);

return ret;
}

X509_CRL *cl_load_crl(const char *file)
Expand Down
Loading