Fix code health issues in the CDM identified by Coverity
Bug: 323331064 Change-Id: Ic87b32c1f7996bd5bb31e99a5fc117c59e94a42c
This commit is contained in:
@@ -115,7 +115,7 @@ OEMCryptoResult EntitlementKeySession::SelectKey(const std::string& key_id,
|
|||||||
|
|
||||||
OEMCrypto_EntitledContentKeyObject EntitlementKeySession::MakeOecEntitledKey(
|
OEMCrypto_EntitledContentKeyObject EntitlementKeySession::MakeOecEntitledKey(
|
||||||
const CryptoKey& input_key, std::string& message) {
|
const CryptoKey& input_key, std::string& message) {
|
||||||
OEMCrypto_EntitledContentKeyObject output_key;
|
OEMCrypto_EntitledContentKeyObject output_key = {};
|
||||||
message.clear();
|
message.clear();
|
||||||
|
|
||||||
const std::string& entitlement_key_id = input_key.entitlement_key_id();
|
const std::string& entitlement_key_id = input_key.entitlement_key_id();
|
||||||
|
|||||||
@@ -301,10 +301,6 @@ void InitVectorConstants() {
|
|||||||
case 3:
|
case 3:
|
||||||
kOverFullUsageEntryInfoVector.push_back(kUsageEntryInfoSecureStop2);
|
kOverFullUsageEntryInfoVector.push_back(kUsageEntryInfoSecureStop2);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
kOverFullUsageEntryInfoVector.push_back(
|
|
||||||
kUsageEntryInfoStorageTypeUnknown);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4136,6 +4132,7 @@ TEST_F(CdmUsageTableTest, DetermineLicenseToRemove_BasicPriorities) {
|
|||||||
CdmUsageEntryInfo streaming_entry_info;
|
CdmUsageEntryInfo streaming_entry_info;
|
||||||
streaming_entry_info.storage_type = kStorageUsageInfo;
|
streaming_entry_info.storage_type = kStorageUsageInfo;
|
||||||
streaming_entry_info.last_use_time = kLruBaseTime;
|
streaming_entry_info.last_use_time = kLruBaseTime;
|
||||||
|
streaming_entry_info.offline_license_expiry_time = 0;
|
||||||
usage_entry_info_list.push_back(streaming_entry_info);
|
usage_entry_info_list.push_back(streaming_entry_info);
|
||||||
constexpr UsageEntryIndex streaming_entry_index = 2;
|
constexpr UsageEntryIndex streaming_entry_index = 2;
|
||||||
|
|
||||||
@@ -4144,6 +4141,7 @@ TEST_F(CdmUsageTableTest, DetermineLicenseToRemove_BasicPriorities) {
|
|||||||
unknown_entry_info.storage_type = kStorageTypeUnknown;
|
unknown_entry_info.storage_type = kStorageTypeUnknown;
|
||||||
// Should be chosen regardless of |last_use_time|.
|
// Should be chosen regardless of |last_use_time|.
|
||||||
unknown_entry_info.last_use_time = kCurrentTime;
|
unknown_entry_info.last_use_time = kCurrentTime;
|
||||||
|
unknown_entry_info.offline_license_expiry_time = 0;
|
||||||
usage_entry_info_list.push_back(unknown_entry_info);
|
usage_entry_info_list.push_back(unknown_entry_info);
|
||||||
constexpr UsageEntryIndex unknown_entry_index = 3;
|
constexpr UsageEntryIndex unknown_entry_index = 3;
|
||||||
|
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ bool HttpSocket::Connect(int timeout_in_ms) {
|
|||||||
if (socket_fd_ < 0) {
|
if (socket_fd_ < 0) {
|
||||||
LOGE("Cannot open socket %s (port %s): errno = %d", domain_name_.c_str(),
|
LOGE("Cannot open socket %s (port %s): errno = %d", domain_name_.c_str(),
|
||||||
port_.c_str(), GetError());
|
port_.c_str(), GetError());
|
||||||
|
freeaddrinfo(addr_info);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,6 +319,7 @@ bool HttpSocket::Connect(int timeout_in_ms) {
|
|||||||
if (ioctlsocket(socket_fd_, FIONBIO, &mode) != 0) {
|
if (ioctlsocket(socket_fd_, FIONBIO, &mode) != 0) {
|
||||||
LOGE("ioctlsocket error %s (port %s), wsa error = %d", domain_name_.c_str(),
|
LOGE("ioctlsocket error %s (port %s), wsa error = %d", domain_name_.c_str(),
|
||||||
port_.c_str(), WSAGetLastError());
|
port_.c_str(), WSAGetLastError());
|
||||||
|
freeaddrinfo(addr_info);
|
||||||
CloseSocket();
|
CloseSocket();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -326,12 +328,14 @@ bool HttpSocket::Connect(int timeout_in_ms) {
|
|||||||
if (original_flags == -1) {
|
if (original_flags == -1) {
|
||||||
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
|
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
|
||||||
port_.c_str(), errno);
|
port_.c_str(), errno);
|
||||||
|
freeaddrinfo(addr_info);
|
||||||
CloseSocket();
|
CloseSocket();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (fcntl(socket_fd_, F_SETFL, original_flags | O_NONBLOCK) == -1) {
|
if (fcntl(socket_fd_, F_SETFL, original_flags | O_NONBLOCK) == -1) {
|
||||||
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
|
LOGE("fcntl error %s (port %s), errno = %d", domain_name_.c_str(),
|
||||||
port_.c_str(), errno);
|
port_.c_str(), errno);
|
||||||
|
freeaddrinfo(addr_info);
|
||||||
CloseSocket();
|
CloseSocket();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ class CdmLicenseTestPeer : public CdmLicense {
|
|||||||
|
|
||||||
using CdmLicense::HandleNewEntitledKeys;
|
using CdmLicense::HandleNewEntitledKeys;
|
||||||
|
|
||||||
void set_entitlement_keys(License license) {
|
void set_entitlement_keys(const License& license) {
|
||||||
entitlement_keys_.CopyFrom(license.key());
|
entitlement_keys_.CopyFrom(license.key());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -619,7 +619,7 @@ TEST_P(CdmLicenseEntitledKeyTest, LoadsEntitledKeys) {
|
|||||||
CreateCdmLicense();
|
CreateCdmLicense();
|
||||||
EXPECT_TRUE(cdm_license_->Init(true, kDefaultServiceCertificate,
|
EXPECT_TRUE(cdm_license_->Init(true, kDefaultServiceCertificate,
|
||||||
crypto_session_, policy_engine_));
|
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
|
// Call the function under test and check its return value
|
||||||
CdmResponseType ret = cdm_license_->HandleNewEntitledKeys(entitled_keys);
|
CdmResponseType ret = cdm_license_->HandleNewEntitledKeys(entitled_keys);
|
||||||
|
|||||||
@@ -34,9 +34,10 @@ void DumpHeader(std::ofstream* out, const std::string& type) {
|
|||||||
|
|
||||||
void DumpHex(std::ofstream* out, const std::string& name,
|
void DumpHex(std::ofstream* out, const std::string& name,
|
||||||
const std::string& value) {
|
const std::string& value) {
|
||||||
|
const auto out_flags = out->flags();
|
||||||
*out << "const uint8_t " << name << "_raw[] = {\n";
|
*out << "const uint8_t " << name << "_raw[] = {\n";
|
||||||
*out << " ";
|
*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 ";
|
if ((i > 0) && (i % 10 == 0)) *out << "\n ";
|
||||||
uint8_t c = value[i];
|
uint8_t c = value[i];
|
||||||
*out << "0x" << std::hex << std::setw(2) << std::setfill('0') << int(c)
|
*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"
|
*out << name << "_ = std::string (\n"
|
||||||
<< " reinterpret_cast<const char *>(" << name << "_raw), \n"
|
<< " reinterpret_cast<const char *>(" << name << "_raw), \n"
|
||||||
<< " sizeof(" << 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) {
|
void LogTimer(const char* field, bool set, int64_t time) {
|
||||||
|
|||||||
Reference in New Issue
Block a user