From 0f0987a29956e8ae8ed8709154954aa0f26afb33 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Fri, 25 Feb 2022 16:38:07 -0500 Subject: [PATCH 1/3] crypto: fix return type prob reportec by coverity Coverity correctly reported that the value returned by BIO_get_mem_data could be negative and the type provided for the return value was unsigned. Fix up the type and check. Signed-off-by: Michael Dawson --- src/crypto/crypto_common.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index dce0774e8fa632..c318453465c64e 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -767,9 +767,9 @@ static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) { return false; } char* oline = nullptr; - size_t n_bytes = BIO_get_mem_data(tmp.get(), &oline); - CHECK_IMPLIES(n_bytes != 0, oline != nullptr); - PrintAltName(out, oline, n_bytes, true, nullptr); + long n_bytes = BIO_get_mem_data(tmp.get(), &oline); // NOLINT(runtime/int) + CHECK_IMPLIES(n_bytes > 0, oline != nullptr); + PrintAltName(out, oline, static_cast(n_bytes), true, nullptr); } else if (gen->type == GEN_IPADD) { BIO_printf(out.get(), "IP Address:"); const ASN1_OCTET_STRING* ip = gen->d.ip; From 8ad6d45d35cc467257f4db3e87e5efe37debd4d0 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 28 Feb 2022 11:12:29 -0500 Subject: [PATCH 2/3] Update src/crypto/crypto_common.cc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tobias Nießen --- src/crypto/crypto_common.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index c318453465c64e..1c183f188c6f3e 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -768,7 +768,8 @@ static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) { } char* oline = nullptr; long n_bytes = BIO_get_mem_data(tmp.get(), &oline); // NOLINT(runtime/int) - CHECK_IMPLIES(n_bytes > 0, oline != nullptr); + CHECK(n_bytes >= 0); + CHECK_IMPLIES(n_bytes != 0, oline != nullptr); PrintAltName(out, oline, static_cast(n_bytes), true, nullptr); } else if (gen->type == GEN_IPADD) { BIO_printf(out.get(), "IP Address:"); From 139c80608ef0eeaa6019d58ff03688f0e38520e5 Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 28 Feb 2022 11:19:18 -0500 Subject: [PATCH 3/3] squash: fixup linter issue --- src/crypto/crypto_common.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 1c183f188c6f3e..2c2e73bc7dc800 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -768,7 +768,7 @@ static bool PrintGeneralName(const BIOPointer& out, const GENERAL_NAME* gen) { } char* oline = nullptr; long n_bytes = BIO_get_mem_data(tmp.get(), &oline); // NOLINT(runtime/int) - CHECK(n_bytes >= 0); + CHECK_GE(n_bytes, 0); CHECK_IMPLIES(n_bytes != 0, oline != nullptr); PrintAltName(out, oline, static_cast(n_bytes), true, nullptr); } else if (gen->type == GEN_IPADD) {