Skip to content

Commit 4de6692

Browse files
committed
Fix test code to not assume NUL terminated strings
ASN.1 strings may not be NUL terminated. Don't assume they are. CVE-2021-3712 Reviewed-by: Viktor Dukhovni <viktor@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org>
1 parent 8393de4 commit 4de6692

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

test/x509_time_test.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,12 @@ static int test_x509_time(int idx)
330330

331331
/* if t is not NULL but expected_string is NULL, it is an 'OK' case too */
332332
if (t != NULL && x509_format_tests[idx].expected_string) {
333-
if (!TEST_str_eq((const char *)t->data,
334-
x509_format_tests[idx].expected_string)) {
335-
TEST_info("test_x509_time(%d) failed: expected_string %s, got %s\n",
336-
idx, x509_format_tests[idx].expected_string, t->data);
333+
if (!TEST_mem_eq((const char *)t->data, t->length,
334+
x509_format_tests[idx].expected_string,
335+
strlen(x509_format_tests[idx].expected_string))) {
336+
TEST_info("test_x509_time(%d) failed: expected_string %s, got %.*s\n",
337+
idx, x509_format_tests[idx].expected_string, t->length,
338+
t->data);
337339
goto out;
338340
}
339341
}

0 commit comments

Comments
 (0)