From: tb Date: Wed, 23 Nov 2022 08:51:05 +0000 (+0000) Subject: asn1_string_to_utf8 test: appease coverity X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=a201dd641c0ccb400edef7e81e23c453d6779580;p=openbsd 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 --- diff --git a/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c b/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c index 2ead7b46c3b..a87969d987f 100644 --- a/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c +++ b/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;