Added missing null checks in CdmSession.
[ Merge of http://go/wvgerrit/85743 ] There were a few methods that did not check that the output parameter was not set to null befor assigning to. The new checks follow a similar pattern that is used for DeviceFiles. Bug: 135207278 Test: Linux unittest and Android tests Change-Id: Idff25a71dd7a6db99f7f9c2dcf4949ac683208cc
This commit is contained in:
@@ -19,6 +19,22 @@
|
||||
#include "wv_cdm_constants.h"
|
||||
#include "wv_cdm_event_listener.h"
|
||||
|
||||
// Stringify turns macro arguments into static C strings.
|
||||
// Example: STRINGIFY(this_argument) -> "this_argument"
|
||||
#define STRINGIFY(PARAM...) #PARAM
|
||||
|
||||
#define RETURN_STATUS_IF_NULL(PARAM) \
|
||||
if ((PARAM) == nullptr) { \
|
||||
LOGE("Output parameter |" STRINGIFY(PARAM) "| not provided"); \
|
||||
return PARAMETER_NULL; \
|
||||
}
|
||||
|
||||
#define RETURN_FALSE_IF_NULL(PARAM) \
|
||||
if ((PARAM) == nullptr) { \
|
||||
LOGE("Output parameter |" STRINGIFY(PARAM) "| not provided"); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
namespace {
|
||||
const size_t kKeySetIdLength = 14;
|
||||
|
||||
@@ -391,11 +407,7 @@ CdmResponseType CdmSession::GenerateKeyRequestInternal(
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
|
||||
if (!key_request) {
|
||||
LOGE("No output destination provided");
|
||||
return PARAMETER_NULL;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(key_request);
|
||||
|
||||
switch (license_type) {
|
||||
case kLicenseTypeTemporary:
|
||||
@@ -561,6 +573,7 @@ CdmResponseType CdmSession::QueryStatus(CdmQueryMap* query_response) {
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(query_response);
|
||||
|
||||
switch (security_level_) {
|
||||
case kSecurityLevelL1:
|
||||
@@ -603,9 +616,10 @@ CdmResponseType CdmSession::QueryKeyAllowedUsage(
|
||||
CdmResponseType CdmSession::QueryOemCryptoSessionId(
|
||||
CdmQueryMap* query_response) {
|
||||
if (!initialized_) {
|
||||
LOGE("Not initialized");
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(query_response);
|
||||
|
||||
(*query_response)[QUERY_KEY_OEMCRYPTO_SESSION_ID] =
|
||||
std::to_string(crypto_session_->oec_session_id());
|
||||
@@ -663,6 +677,8 @@ CdmResponseType CdmSession::GenerateRenewalRequest(CdmKeyRequest* key_request) {
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(key_request);
|
||||
|
||||
CdmResponseType status = license_parser_->PrepareKeyUpdateRequest(
|
||||
true, app_parameters_, nullptr, &key_request->message, &key_request->url);
|
||||
|
||||
@@ -706,6 +722,7 @@ CdmResponseType CdmSession::GenerateReleaseRequest(CdmKeyRequest* key_request) {
|
||||
LOGE("CDM session not initialized");
|
||||
return NOT_INITIALIZED_ERROR;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(key_request);
|
||||
is_release_ = true;
|
||||
license_request_latency_.Clear();
|
||||
CdmResponseType status = license_parser_->PrepareKeyUpdateRequest(
|
||||
@@ -813,10 +830,7 @@ CdmSessionId CdmSession::GenerateSessionId() {
|
||||
}
|
||||
|
||||
bool CdmSession::GenerateKeySetId(CdmKeySetId* key_set_id) {
|
||||
if (!key_set_id) {
|
||||
LOGW("Key set ID destination not provided");
|
||||
return false;
|
||||
}
|
||||
RETURN_FALSE_IF_NULL(key_set_id);
|
||||
|
||||
std::vector<uint8_t> random_data(
|
||||
(kKeySetIdLength - sizeof(KEY_SET_ID_PREFIX)) / 2, 0);
|
||||
@@ -1062,10 +1076,7 @@ CdmResponseType CdmSession::GenericEncrypt(const std::string& in_buffer,
|
||||
const std::string& iv,
|
||||
CdmEncryptionAlgorithm algorithm,
|
||||
std::string* out_buffer) {
|
||||
if (!out_buffer) {
|
||||
LOGE("No output destination provided");
|
||||
return PARAMETER_NULL;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(out_buffer);
|
||||
CdmResponseType sts;
|
||||
M_TIME(sts = crypto_session_->GenericEncrypt(in_buffer, key_id, iv, algorithm,
|
||||
out_buffer),
|
||||
@@ -1079,10 +1090,7 @@ CdmResponseType CdmSession::GenericDecrypt(const std::string& in_buffer,
|
||||
const std::string& iv,
|
||||
CdmEncryptionAlgorithm algorithm,
|
||||
std::string* out_buffer) {
|
||||
if (!out_buffer) {
|
||||
LOGE("No output destination provided");
|
||||
return PARAMETER_NULL;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(out_buffer);
|
||||
CdmResponseType sts;
|
||||
M_TIME(sts = crypto_session_->GenericDecrypt(in_buffer, key_id, iv, algorithm,
|
||||
out_buffer),
|
||||
@@ -1095,10 +1103,7 @@ CdmResponseType CdmSession::GenericSign(const std::string& message,
|
||||
const std::string& key_id,
|
||||
CdmSigningAlgorithm algorithm,
|
||||
std::string* signature) {
|
||||
if (!signature) {
|
||||
LOGE("No output destination provided");
|
||||
return PARAMETER_NULL;
|
||||
}
|
||||
RETURN_STATUS_IF_NULL(signature);
|
||||
CdmResponseType sts;
|
||||
M_TIME(
|
||||
sts = crypto_session_->GenericSign(message, key_id, algorithm, signature),
|
||||
|
||||
Reference in New Issue
Block a user