Merge "Resize OEMCrypto buffer-based results on success." into tm-dev am: f980049ef0 am: 3adda51fc2

Original change: https://googleplex-android-review.googlesource.com/c/platform/vendor/widevine/+/18126088

Change-Id: Ie65372e74a6b8b5f73dfeaaef33f3a67d4e4e58a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Alex Dale
2022-05-05 21:28:16 +00:00
committed by Automerger Merge Worker
4 changed files with 85 additions and 44 deletions

View File

@@ -2104,6 +2104,11 @@ CdmResponseType CryptoSession::LoadProvisioning(
metrics_, oemcrypto_load_provisioning_, status);
});
if (status == OEMCrypto_SUCCESS) {
wrapped_private_key->resize(wrapped_private_key_length);
return NO_ERROR;
}
wrapped_private_key->clear();
return MapOEMCryptoResult(status, LOAD_PROVISIONING_ERROR,
"LoadProvisioning");
}
@@ -2288,29 +2293,25 @@ bool CryptoSession::GetBuildInformation(RequestedSecurityLevel security_level,
RequestedSecurityLevelToString(security_level));
RETURN_IF_UNINITIALIZED(false);
RETURN_IF_NULL(info, false);
OEMCryptoResult build_information;
std::string buf;
size_t buf_length = 0;
WithOecReadLock("GetBuildInformation", [&] {
build_information =
OEMCrypto_BuildInformation(&buf[0], &buf_length, security_level);
size_t info_length = 128;
info->assign(info_length, '\0');
OEMCryptoResult result = WithOecReadLock("GetBuildInformation", [&] {
return OEMCrypto_BuildInformation(&info->front(), &info_length,
security_level);
});
if (build_information == OEMCrypto_ERROR_SHORT_BUFFER) {
buf.resize(buf_length);
WithOecReadLock("GetBuildInformation Attempt 2", [&] {
build_information =
OEMCrypto_BuildInformation(&buf[0], &buf_length, security_level);
if (result == OEMCrypto_ERROR_SHORT_BUFFER) {
info->assign(info_length, '\0');
result = WithOecReadLock("GetBuildInformation Attempt 2", [&] {
return OEMCrypto_BuildInformation(&info->front(), &info_length,
security_level);
});
}
if (build_information == OEMCrypto_SUCCESS) {
*info = buf;
} else {
LOGE("Unexpected return value");
if (result != OEMCrypto_SUCCESS) {
LOGE("GetBuildInformation failed: result = %d", result);
info->clear();
return false;
}
info->resize(info_length);
return true;
}

View File

@@ -1737,14 +1737,19 @@ OEMCryptoResult OEMCrypto_BuildInformation(
if (fcn->BuildInformation_V16 == nullptr) {
return OEMCrypto_ERROR_NOT_IMPLEMENTED;
}
if (buffer_length == nullptr) return OEMCrypto_ERROR_INVALID_CONTEXT;
if (buffer == nullptr && *buffer_length > 0)
return OEMCrypto_ERROR_INVALID_CONTEXT;
constexpr size_t kMaxBuildInfoLength = 128;
const char* build_info = fcn->BuildInformation_V16();
size_t max_length = strnlen(build_info, 128);
if (*buffer_length < max_length) {
*buffer_length = max_length;
if (build_info == nullptr) return OEMCrypto_ERROR_UNKNOWN_FAILURE;
const size_t build_info_length = strnlen(build_info, kMaxBuildInfoLength);
if (*buffer_length < build_info_length) {
*buffer_length = build_info_length;
return OEMCrypto_ERROR_SHORT_BUFFER;
}
*buffer_length = max_length;
memcpy(buffer, build_info, *buffer_length);
*buffer_length = build_info_length;
memcpy(buffer, build_info, build_info_length);
return OEMCrypto_SUCCESS;
}
return fcn->BuildInformation(buffer, buffer_length);