Skip to content

Commit 43aa658

Browse files
author
tb
committed
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
1 parent 014e632 commit 43aa658

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/regress/lib/libcrypto/asn1/asn1_string_to_utf8.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: asn1_string_to_utf8.c,v 1.1 2022/05/16 20:53:20 tb Exp $ */
1+
/* $OpenBSD: asn1_string_to_utf8.c,v 1.2 2022/11/23 08:51:05 tb Exp $ */
22
/*
33
* Copyright (c) 2022 Theo Buehler <tb@openbsd.org>
44
*
@@ -86,12 +86,18 @@ asn1_string_to_utf8_test(const struct asn1_string_to_utf8_test_case *test)
8686
goto err;
8787
}
8888

89-
if ((ret = ASN1_STRING_to_UTF8(&out, str)) != test->want_len) {
89+
if ((ret = ASN1_STRING_to_UTF8(&out, str)) < 0) {
9090
warnx("ASN1_STRING_to_UTF8 failed: got %d, want %d", ret,
9191
test->want_len);
9292
goto err;
9393
}
9494

95+
if (ret != test->want_len) {
96+
warnx("ASN1_STRING_to_UTF8: got %d, want %d", ret,
97+
test->want_len);
98+
goto err;
99+
}
100+
95101
if (memcmp(out, test->want, test->want_len) != 0) {
96102
warnx("memcmp failed");
97103
goto err;

0 commit comments

Comments
 (0)