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:
@@ -2,41 +2,41 @@
|
||||
// source code may only be used and distributed under the Widevine
|
||||
// License Agreement.
|
||||
|
||||
#include "FuzzedDataProvider.h"
|
||||
#include "oemcrypto_fuzz_helper.h"
|
||||
#include "oemcrypto_fuzz_structs.h"
|
||||
|
||||
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();
|
||||
if (size < sizeof(OEMCrypto_Renewal_Response_Fuzz)) {
|
||||
return 0;
|
||||
}
|
||||
wvoec::RedirectStdoutToFile();
|
||||
|
||||
// Copy input data to OEMCrypto_Renewal_Response_Fuzz and rest of message
|
||||
// into encrypted license_renewal_response.
|
||||
OEMCrypto_Renewal_Response_Fuzz fuzzed_data;
|
||||
memcpy(&fuzzed_data, data, sizeof(fuzzed_data));
|
||||
const uint8_t* renewal_response =
|
||||
data + sizeof(OEMCrypto_Renewal_Response_Fuzz);
|
||||
const size_t renewal_response_size =
|
||||
size - sizeof(OEMCrypto_Renewal_Response_Fuzz);
|
||||
wvoec::OEMCrypto_Renewal_Response_Fuzz fuzzed_structure;
|
||||
if (size < sizeof(fuzzed_structure)) {
|
||||
return 0;
|
||||
}
|
||||
FuzzedDataProvider fuzzed_data(data, size);
|
||||
fuzzed_data.ConsumeData(&fuzzed_structure, sizeof(fuzzed_structure));
|
||||
const std::vector<uint8_t> renewal_response =
|
||||
fuzzed_data.ConsumeRemainingBytes<uint8_t>();
|
||||
|
||||
OEMCryptoRenewalAPIFuzz renewal_response_fuzz;
|
||||
wvoec::OEMCryptoRenewalAPIFuzz renewal_response_fuzz;
|
||||
renewal_response_fuzz.Intialize();
|
||||
renewal_response_fuzz.license_messages().SignAndVerifyRequest();
|
||||
renewal_response_fuzz.license_messages().CreateDefaultResponse();
|
||||
|
||||
// Inject timer limits from fuzzed input to timer_limits field from
|
||||
// core license response.
|
||||
renewal_response_fuzz.license_messages().InjectFuzzedTimerLimits(fuzzed_data);
|
||||
renewal_response_fuzz.license_messages().InjectFuzzedTimerLimits(
|
||||
fuzzed_structure);
|
||||
renewal_response_fuzz.license_messages().EncryptAndSignResponse();
|
||||
renewal_response_fuzz.license_messages().LoadResponse();
|
||||
|
||||
// Call renewal response API using fuzzed data.
|
||||
renewal_response_fuzz.renewal_messages().SignAndVerifyRequest();
|
||||
renewal_response_fuzz.renewal_messages().InjectFuzzedResponseData(
|
||||
fuzzed_data, renewal_response, renewal_response_size);
|
||||
fuzzed_structure, renewal_response.data(), renewal_response.size());
|
||||
renewal_response_fuzz.renewal_messages().LoadResponse();
|
||||
renewal_response_fuzz.Terminate();
|
||||
return 0;
|
||||
}
|
||||
} // namespace wvoec
|
||||
Reference in New Issue
Block a user