Skip to content

Commit d0134f2

Browse files
committed
coverity: address reuse after free, add NULL checks
1 parent 2d892f0 commit d0134f2

1 file changed

Lines changed: 51 additions & 29 deletions

File tree

tests/api.c

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20906,21 +20906,33 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
2090620906
/* offset_sec = -45 * min;*/
2090720907
ExpectNotNull(asn_time =
2090820908
wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec));
20909-
ExpectTrue(asn_time->type == asn_utc_time);
20910-
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20911-
CTC_DATE_SIZE));
20912-
date_str[CTC_DATE_SIZE] = '\0';
20913-
ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
20909+
if (asn_time != NULL) {
20910+
ExpectTrue(asn_time->type == asn_utc_time);
20911+
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20912+
CTC_DATE_SIZE));
20913+
date_str[CTC_DATE_SIZE] = '\0';
20914+
ExpectIntEQ(0, XMEMCMP(date_str, "000222211500Z", 13));
20915+
if (asn_time != s) {
20916+
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20917+
}
20918+
asn_time = NULL;
20919+
}
2091420920

2091520921
/* negative offset */
2091620922
offset_sec = -45 * mini;
2091720923
asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day, offset_sec);
2091820924
ExpectNotNull(asn_time);
20919-
ExpectTrue(asn_time->type == asn_utc_time);
20920-
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20921-
CTC_DATE_SIZE));
20922-
date_str[CTC_DATE_SIZE] = '\0';
20923-
ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
20925+
if (asn_time != NULL) {
20926+
ExpectTrue(asn_time->type == asn_utc_time);
20927+
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20928+
CTC_DATE_SIZE));
20929+
date_str[CTC_DATE_SIZE] = '\0';
20930+
ExpectIntEQ(0, XMEMCMP(date_str, "000222194500Z", 13));
20931+
if (asn_time != s) {
20932+
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20933+
}
20934+
asn_time = NULL;
20935+
}
2092420936

2092520937
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
2092620938
s = NULL;
@@ -20937,11 +20949,17 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
2093720949
offset_sec = 10 * mini;
2093820950
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
2093920951
offset_sec));
20940-
ExpectTrue(asn_time->type == asn_gen_time);
20941-
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20942-
CTC_DATE_SIZE));
20943-
date_str[CTC_DATE_SIZE] = '\0';
20944-
ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
20952+
if (asn_time != NULL) {
20953+
ExpectTrue(asn_time->type == asn_gen_time);
20954+
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20955+
CTC_DATE_SIZE));
20956+
date_str[CTC_DATE_SIZE] = '\0';
20957+
ExpectIntEQ(0, XMEMCMP(date_str, "20550313091000Z", 15));
20958+
if (asn_time != s) {
20959+
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20960+
}
20961+
asn_time = NULL;
20962+
}
2094520963

2094620964
XFREE(s, NULL, DYNAMIC_TYPE_OPENSSL);
2094720965
s = NULL;
@@ -20956,22 +20974,26 @@ static int test_wolfSSL_ASN1_TIME_adj(void)
2095620974
offset_sec = 45 * mini;
2095720975
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(s, t, offset_day,
2095820976
offset_sec));
20959-
ExpectTrue(asn_time->type == asn_utc_time);
20960-
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20961-
CTC_DATE_SIZE));
20962-
date_str[CTC_DATE_SIZE] = '\0';
20963-
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
20964-
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20965-
asn_time = NULL;
20966-
20977+
if (asn_time != NULL) {
20978+
ExpectTrue(asn_time->type == asn_utc_time);
20979+
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20980+
CTC_DATE_SIZE));
20981+
date_str[CTC_DATE_SIZE] = '\0';
20982+
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
20983+
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20984+
asn_time = NULL;
20985+
}
2096720986
ExpectNotNull(asn_time = wolfSSL_ASN1_TIME_adj(NULL, t, offset_day,
2096820987
offset_sec));
20969-
ExpectTrue(asn_time->type == asn_utc_time);
20970-
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20971-
CTC_DATE_SIZE));
20972-
date_str[CTC_DATE_SIZE] = '\0';
20973-
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
20974-
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20988+
if (asn_time != NULL) {
20989+
ExpectTrue(asn_time->type == asn_utc_time);
20990+
ExpectNotNull(XSTRNCPY(date_str, (const char*)&asn_time->data,
20991+
CTC_DATE_SIZE));
20992+
date_str[CTC_DATE_SIZE] = '\0';
20993+
ExpectIntEQ(0, XMEMCMP(date_str, "000222211515Z", 13));
20994+
XFREE(asn_time, NULL, DYNAMIC_TYPE_OPENSSL);
20995+
asn_time = NULL;
20996+
}
2097520997
#endif
2097620998
return EXPECT_RESULT();
2097720999
}

0 commit comments

Comments
 (0)