Fix test/asn1_encode_test.c to handle encoding/decoding failure

Make it only report (and fail on) encoding/decoding failures when success
is expected.

Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16036)
This commit is contained in:
Richard Levitte 2021-07-09 08:51:55 +02:00
parent f0f4de4e50
commit 50d0a51d6d

View File

@ -742,14 +742,17 @@ static int test_intern(const TEST_PACKAGE *package)
sizeof(test_custom_data) / sizeof(test_custom_data[0])); sizeof(test_custom_data) / sizeof(test_custom_data[0]));
for (i = 0; i < nelems; i++) { for (i = 0; i < nelems; i++) {
size_t pos = i * package->encode_expectations_elem_size; size_t pos = i * package->encode_expectations_elem_size;
switch (do_encode_custom((EXPECTED *)&((unsigned char *)package EXPECTED *expected
->encode_expectations)[pos], = (EXPECTED *)&((unsigned char *)package->encode_expectations)[pos];
&test_custom_data[i], package)) {
switch (do_encode_custom(expected, &test_custom_data[i], package)) {
case -1: case -1:
TEST_error("Failed custom encode round trip %u of %s", if (expected->success) {
i, package->name); TEST_error("Failed custom encode round trip %u of %s",
TEST_openssl_errors(); i, package->name);
fail++; TEST_openssl_errors();
fail++;
}
break; break;
case 0: case 0:
TEST_error("Custom encode round trip %u of %s mismatch", TEST_error("Custom encode round trip %u of %s mismatch",
@ -763,16 +766,16 @@ static int test_intern(const TEST_PACKAGE *package)
OPENSSL_die("do_encode_custom() return unknown value", OPENSSL_die("do_encode_custom() return unknown value",
__FILE__, __LINE__); __FILE__, __LINE__);
} }
switch (do_decode_custom(&test_custom_data[i], switch (do_decode_custom(&test_custom_data[i], expected,
(EXPECTED *)&((unsigned char *)package
->encode_expectations)[pos],
package->encode_expectations_elem_size, package->encode_expectations_elem_size,
package)) { package)) {
case -1: case -1:
TEST_error("Failed custom decode round trip %u of %s", if (expected->success) {
i, package->name); TEST_error("Failed custom decode round trip %u of %s",
TEST_openssl_errors(); i, package->name);
fail++; TEST_openssl_errors();
fail++;
}
break; break;
case 0: case 0:
TEST_error("Custom decode round trip %u of %s mismatch", TEST_error("Custom decode round trip %u of %s mismatch",
@ -792,15 +795,17 @@ static int test_intern(const TEST_PACKAGE *package)
nelems = package->encdec_data_size / package->encdec_data_elem_size; nelems = package->encdec_data_size / package->encdec_data_elem_size;
for (i = 0; i < nelems; i++) { for (i = 0; i < nelems; i++) {
size_t pos = i * package->encdec_data_elem_size; size_t pos = i * package->encdec_data_elem_size;
switch (do_enc_dec((EXPECTED *)&((unsigned char *)package EXPECTED *expected
->encdec_data)[pos], = (EXPECTED *)&((unsigned char *)package->encdec_data)[pos];
package->encdec_data_elem_size,
package)) { switch (do_enc_dec(expected, package->encdec_data_elem_size, package)) {
case -1: case -1:
TEST_error("Failed encode/decode round trip %u of %s", if (expected->success) {
i, package->name); TEST_error("Failed encode/decode round trip %u of %s",
TEST_openssl_errors(); i, package->name);
fail++; TEST_openssl_errors();
fail++;
}
break; break;
case 0: case 0:
TEST_error("Encode/decode round trip %u of %s mismatch", TEST_error("Encode/decode round trip %u of %s mismatch",