Clean up fuzz helper classes

- Remove OEMCrypto state changes hidden in constructors and destructors.
- Use composition instead of inheritance to structure classes.
- Avoid calling non-trivial destructors for objects with static
  lifetime.

Merged from https://widevine-internal-review.googlesource.com/168497
Merged from https://widevine-internal-review.googlesource.com/171170
Merged from https://widevine-internal-review.googlesource.com/171171
Merged from https://widevine-internal-review.googlesource.com/171870

Change-Id: I20476a7b1132d11f011b8650ec01e3c2dc3fc0e8
This commit is contained in:
Ian Benz
2023-03-20 17:46:15 +00:00
committed by Robert Shih
parent af070601b0
commit 53fe55cb72
30 changed files with 518 additions and 398 deletions

View File

@@ -9,23 +9,21 @@
#include "OEMCryptoCENC.h"
#include "oemcrypto_fuzz_helper.h"
using namespace wvoec;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
// Redirect printf and log statements from oemcrypto functions to a file to
// reduce noise
RedirectStdoutToFile();
wvoec::RedirectStdoutToFile();
wvoec::OEMCryptoLicenseAPIFuzz license_api_fuzz;
license_api_fuzz.Initialize();
OEMCryptoLicenseAPIFuzz license_api_fuzz;
FuzzedDataProvider fuzzed_data(data, size);
if (fuzzed_data.ConsumeBool()) {
license_api_fuzz.license_messages().set_control(
license_api_fuzz.license_messages().control() |
kControlAllowHashVerification);
wvoec::kControlAllowHashVerification);
}
const uint32_t session_id = license_api_fuzz.session()->session_id();
const uint32_t session_id = license_api_fuzz.session().session_id();
const std::array<uint8_t, 16> content_key_id{};
const uint32_t frame_number = fuzzed_data.ConsumeIntegral<uint32_t>();
std::array<OEMCrypto_SharedMemory, 1> sample_buffer{};
@@ -62,13 +60,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
license_api_fuzz.LoadLicense();
std::vector<uint8_t> key_handle;
GetKeyHandleIntoVector(session_id, content_key_id.data(),
content_key_id.size(), OEMCrypto_CipherMode_CENC,
key_handle);
wvoec::GetKeyHandleIntoVector(session_id, content_key_id.data(),
content_key_id.size(),
OEMCrypto_CipherMode_CENC, key_handle);
OEMCrypto_SetDecryptHash(session_id, frame_number, hash.data(), hash.size());
OEMCrypto_DecryptCENC(key_handle.data(), key_handle.size(), &sample, 1,
&pattern);
OEMCrypto_GetHashErrorCode(session_id, failed_frame_number);
license_api_fuzz.Terminate();
return 0;
}