Fix code health issues in the CDM identified by Coverity

Bug: 323331064
Change-Id: Ic87b32c1f7996bd5bb31e99a5fc117c59e94a42c
This commit is contained in:
Ian Benz
2024-01-30 21:12:56 +00:00
committed by Robert Shih
parent 93c19cd8de
commit 2fabef5bc9
5 changed files with 12 additions and 9 deletions

View File

@@ -115,7 +115,7 @@ OEMCryptoResult EntitlementKeySession::SelectKey(const std::string& key_id,
OEMCrypto_EntitledContentKeyObject EntitlementKeySession::MakeOecEntitledKey(
const CryptoKey& input_key, std::string& message) {
OEMCrypto_EntitledContentKeyObject output_key;
OEMCrypto_EntitledContentKeyObject output_key = {};
message.clear();
const std::string& entitlement_key_id = input_key.entitlement_key_id();

View File

@@ -301,10 +301,6 @@ void InitVectorConstants() {
case 3:
kOverFullUsageEntryInfoVector.push_back(kUsageEntryInfoSecureStop2);
break;
default:
kOverFullUsageEntryInfoVector.push_back(
kUsageEntryInfoStorageTypeUnknown);
break;
}
}
@@ -4136,6 +4132,7 @@ TEST_F(CdmUsageTableTest, DetermineLicenseToRemove_BasicPriorities) {
CdmUsageEntryInfo streaming_entry_info;
streaming_entry_info.storage_type = kStorageUsageInfo;
streaming_entry_info.last_use_time = kLruBaseTime;
streaming_entry_info.offline_license_expiry_time = 0;
usage_entry_info_list.push_back(streaming_entry_info);
constexpr UsageEntryIndex streaming_entry_index = 2;
@@ -4144,6 +4141,7 @@ TEST_F(CdmUsageTableTest, DetermineLicenseToRemove_BasicPriorities) {
unknown_entry_info.storage_type = kStorageTypeUnknown;
// Should be chosen regardless of |last_use_time|.
unknown_entry_info.last_use_time = kCurrentTime;
unknown_entry_info.offline_license_expiry_time = 0;
usage_entry_info_list.push_back(unknown_entry_info);
constexpr UsageEntryIndex unknown_entry_index = 3;

View File

@@ -309,6 +309,7 @@ bool HttpSocket::Connect(int timeout_in_ms) {
if (socket_fd_ < 0) {
LOGE("Cannot open socket %s (port %s): errno = %d", domain_name_.c_str(),
port_.c_str(), GetError());
freeaddrinfo(addr_info);
return false;
}
@@ -318,6 +319,7 @@ bool HttpSocket::Connect(int timeout_in_ms) {
if (ioctlsocket(socket_fd_, FIONBIO, &mode) != 0) {
LOGE("ioctlsocket error %s (port %s), wsa error = %d", domain_name_.c_str(),
port_.c_str(), WSAGetLastError());
freeaddrinfo(addr_info);
CloseSocket();
return false;
}
@@ -326,12 +328,14 @@ bool HttpSocket::Connect(int timeout_in_ms) {
if (original_flags == -1) {
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
port_.c_str(), errno);
freeaddrinfo(addr_info);
CloseSocket();
return false;
}
if (fcntl(socket_fd_, F_SETFL, original_flags | O_NONBLOCK) == -1) {
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
port_.c_str(), errno);
freeaddrinfo(addr_info);
CloseSocket();
return false;
}

View File

@@ -206,7 +206,7 @@ class CdmLicenseTestPeer : public CdmLicense {
using CdmLicense::HandleNewEntitledKeys;
void set_entitlement_keys(License license) {
void set_entitlement_keys(const License& license) {
entitlement_keys_.CopyFrom(license.key());
}
};
@@ -619,7 +619,7 @@ TEST_P(CdmLicenseEntitledKeyTest, LoadsEntitledKeys) {
CreateCdmLicense();
EXPECT_TRUE(cdm_license_->Init(true, kDefaultServiceCertificate,
crypto_session_, policy_engine_));
cdm_license_->set_entitlement_keys(std::move(entitlement_license));
cdm_license_->set_entitlement_keys(entitlement_license);
// Call the function under test and check its return value
CdmResponseType ret = cdm_license_->HandleNewEntitledKeys(entitled_keys);

View File

@@ -34,9 +34,10 @@ void DumpHeader(std::ofstream* out, const std::string& type) {
void DumpHex(std::ofstream* out, const std::string& name,
const std::string& value) {
const auto out_flags = out->flags();
*out << "const uint8_t " << name << "_raw[] = {\n";
*out << " ";
for (unsigned int i = 0; i < value.length(); i++) {
for (size_t i = 0; i < value.length(); i++) {
if ((i > 0) && (i % 10 == 0)) *out << "\n ";
uint8_t c = value[i];
*out << "0x" << std::hex << std::setw(2) << std::setfill('0') << int(c)
@@ -46,7 +47,7 @@ void DumpHex(std::ofstream* out, const std::string& name,
*out << name << "_ = std::string (\n"
<< " reinterpret_cast<const char *>(" << name << "_raw), \n"
<< " sizeof(" << name << "_raw));\n";
*out << std::dec; // Turn off hex when we're done.
out->flags(out_flags); // Restore flags when we're done.
}
void LogTimer(const char* field, bool set, int64_t time) {