mirror of https://github.com/wolfSSL/wolfssl.git
coverity: address reuse after free, add NULL checks
parent
2d892f07eb
commit
d0134f2212
80
tests/api.c
80
tests/api.c
|
@ -20906,21 +20906,33 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
|
||||||
/* offset_sec = -45 * min;*/
|
/* offset_sec = -45 * min;*/
|
||||||
ExpectNotNull(asn_time =
|
ExpectNotNull(asn_time =
|
||||||
wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
|
wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
|
||||||
ExpectTrue(asn_time->type == asn_utc_time);
|
if (asn_time != NULL) {
|
||||||
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
ExpectTrue(asn_time->type == asn_utc_time);
|
||||||
CTC_DATE_SIZE));
|
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
||||||
date_str[CTC_DATE_SIZE] = '\0';
|
CTC_DATE_SIZE));
|
||||||
ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
|
date_str[CTC_DATE_SIZE] = '\0';
|
||||||
|
ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
|
||||||
|
if (asn_time != s) {
|
||||||
|
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
}
|
||||||
|
asn_time = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* negative offset */
|
/* negative offset */
|
||||||
offset_sec = -45 * mini;
|
offset_sec = -45 * mini;
|
||||||
asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
|
asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
|
||||||
ExpectNotNull(asn_time);
|
ExpectNotNull(asn_time);
|
||||||
ExpectTrue(asn_time->type == asn_utc_time);
|
if (asn_time != NULL) {
|
||||||
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
ExpectTrue(asn_time->type == asn_utc_time);
|
||||||
CTC_DATE_SIZE));
|
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
||||||
date_str[CTC_DATE_SIZE] = '\0';
|
CTC_DATE_SIZE));
|
||||||
ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
|
date_str[CTC_DATE_SIZE] = '\0';
|
||||||
|
ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
|
||||||
|
if (asn_time != s) {
|
||||||
|
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
}
|
||||||
|
asn_time = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
|
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
@ -20937,11 +20949,17 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
|
||||||
offset_sec = 10 * mini;
|
offset_sec = 10 * mini;
|
||||||
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
|
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
|
||||||
offset_sec));
|
offset_sec));
|
||||||
ExpectTrue(asn_time->type == asn_gen_time);
|
if (asn_time != NULL) {
|
||||||
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
ExpectTrue(asn_time->type == asn_gen_time);
|
||||||
CTC_DATE_SIZE));
|
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
||||||
date_str[CTC_DATE_SIZE] = '\0';
|
CTC_DATE_SIZE));
|
||||||
ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
|
date_str[CTC_DATE_SIZE] = '\0';
|
||||||
|
ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
|
||||||
|
if (asn_time != s) {
|
||||||
|
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
}
|
||||||
|
asn_time = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
|
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
s = NULL;
|
s = NULL;
|
||||||
|
@ -20956,22 +20974,26 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
|
||||||
offset_sec = 45 * mini;
|
offset_sec = 45 * mini;
|
||||||
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
|
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
|
||||||
offset_sec));
|
offset_sec));
|
||||||
ExpectTrue(asn_time->type == asn_utc_time);
|
if (asn_time != NULL) {
|
||||||
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
ExpectTrue(asn_time->type == asn_utc_time);
|
||||||
CTC_DATE_SIZE));
|
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
||||||
date_str[CTC_DATE_SIZE] = '\0';
|
CTC_DATE_SIZE));
|
||||||
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
|
date_str[CTC_DATE_SIZE] = '\0';
|
||||||
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
|
||||||
asn_time = NULL;
|
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
asn_time = NULL;
|
||||||
|
}
|
||||||
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
|
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
|
||||||
offset_sec));
|
offset_sec));
|
||||||
ExpectTrue(asn_time->type == asn_utc_time);
|
if (asn_time != NULL) {
|
||||||
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
ExpectTrue(asn_time->type == asn_utc_time);
|
||||||
CTC_DATE_SIZE));
|
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
|
||||||
date_str[CTC_DATE_SIZE] = '\0';
|
CTC_DATE_SIZE));
|
||||||
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
|
date_str[CTC_DATE_SIZE] = '\0';
|
||||||
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
|
||||||
|
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
|
||||||
|
asn_time = NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return EXPECT_RESULT();
|
return EXPECT_RESULT();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue