From ada8f63ac13903c0fcbae23ce5fc73ef9e984da5 Mon Sep 17 00:00:00 2001 From: tb <> Date: Wed, 23 Nov 2022 08:51:05 +0000 Subject: asn1_string_to_utf8 test: appease coverity Check for ASN_STRING_to_UTF8() failure before checking it matches our expectations. This should convey clearly that test->want_len is never negative. CID 377011 Diagnosed by jsing --- src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c b/src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c index 2ead7b46c3..a87969d987 100644 --- a/src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c +++ b/src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c @@ -1,4 +1,4 @@ -/* $OpenBSD: asn1_string_to_utf8.c,v 1.1 2022/05/16 20:53:20 tb Exp $ */ +/* $OpenBSD: asn1_string_to_utf8.c,v 1.2 2022/11/23 08:51:05 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler * @@ -86,12 +86,18 @@ asn1_string_to_utf8_test(const struct asn1_string_to_utf8_test_case *test) goto err; } - if ((ret = ASN1_STRING_to_UTF8(&out, str)) != test->want_len) { + if ((ret = ASN1_STRING_to_UTF8(&out, str)) < 0) { warnx("ASN1_STRING_to_UTF8 failed: got %d, want %d", ret, test->want_len); goto err; } + if (ret != test->want_len) { + warnx("ASN1_STRING_to_UTF8: got %d, want %d", ret, + test->want_len); + goto err; + } + if (memcmp(out, test->want, test->want_len) != 0) { warnx("memcmp failed"); goto err; -- cgit v1.2.3-55-g6feb