Skip to content
Open
Changes from 2 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
44 changes: 26 additions & 18 deletions libclamav/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -1748,8 +1748,9 @@ X509 *cl_load_cert(const char *certpath)

struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
{
struct tm *t;
char *str;
struct tm *ret = NULL;
struct tm *t = NULL;
char *str = NULL;
const char *fmt = NULL;
time_t localt;
#ifdef _WIN32
Expand All @@ -1758,18 +1759,21 @@ struct tm *cl_ASN1_GetTimeT(ASN1_TIME *timeobj)
struct tm localtm;
#endif

if (!(timeobj) || !(timeobj->data))
return NULL;
if (!(timeobj))
Comment thread
bob-beck marked this conversation as resolved.
Outdated
goto err;

if ((str = strndup(ASN1_STRING_get0_data(timeobj),
ASN1_STRING_length(timeobj))) == NULL)
goto err;

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

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

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 err;

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

/* 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;

err:
free(t);
free(str);

return ret;
}

X509_CRL *cl_load_crl(const char *file)
Expand Down