-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreation_blob_fuzzer.cc
41 lines (33 loc) · 1.23 KB
/
creation_blob_fuzzer.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Fuzzer that tests parsing and serialization of creation blobs.
#include <stddef.h>
#include <stdint.h>
#include <string>
#include "base/logging.h"
#include "trunks/blob_parser.h"
struct Environment {
Environment() {
logging::SetMinLogLevel(logging::LOG_FATAL); // Disable logging.
}
};
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
if (size < 1)
return 0;
static Environment env;
static trunks::BlobParser blob_parser;
// Parse.
std::string creation_blob(reinterpret_cast<const char*>(data), size);
trunks::TPM2B_CREATION_DATA creation_data;
trunks::TPM2B_DIGEST creation_hash;
trunks::TPMT_TK_CREATION creation_ticket;
if (!blob_parser.ParseCreationBlob(creation_blob, &creation_data,
&creation_hash, &creation_ticket))
return 0; // Quit early on failure to avoid serializing unitialized data.
// Serialize.
std::string serialized;
blob_parser.SerializeCreationBlob(creation_data, creation_hash,
creation_ticket, &serialized);
return 0;
}