Skip to content

Commit

Permalink
crypto: fix return type prob reported by coverity
Browse files Browse the repository at this point in the history
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 <mdawson@devrus.com>

PR-URL: #42135
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
mhdawson committed Mar 1, 2022
1 parent 3ba4124 commit a9c0689
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crypto/crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -741,9 +741,10 @@ 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);
long n_bytes = BIO_get_mem_data(tmp.get(), &oline); // NOLINT(runtime/int)
CHECK_GE(n_bytes, 0);
CHECK_IMPLIES(n_bytes != 0, oline != nullptr);
PrintAltName(out, oline, n_bytes, true, nullptr);
PrintAltName(out, oline, static_cast<size_t>(n_bytes), true, nullptr);
} else if (gen->type == GEN_IPADD) {
BIO_printf(out.get(), "IP Address:");
const ASN1_OCTET_STRING* ip = gen->d.ip;
Expand Down

0 comments on commit a9c0689

Please sign in to comment.