blob: baa0cd2b313e35dfa6e29ad42669c80a62f4f993 [file] [log] [blame]
Andrew Scull190b4382021-10-13 18:38:51 +00001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
Andrew Scull73454b32023-08-17 17:40:49 +000015#include "dice/android.h"
Andrew Scull190b4382021-10-13 18:38:51 +000016#include "dice/fuzz_utils.h"
17#include "dice/utils.h"
18#include "fuzzer/FuzzedDataProvider.h"
19
20using dice::fuzz::ConsumeRandomLengthStringAsBytesFrom;
21using dice::fuzz::FuzzedInputValues;
22
23extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
24 // Exit early if there might not be enough data to fill buffers.
25 if (size < 512) {
26 return 0;
27 }
28
29 FuzzedDataProvider fdp(data, size);
30
31 // Prepare the fuzzed inputs.
32 auto input_values = FuzzedInputValues::ConsumeFrom(fdp);
Andrew Scull73454b32023-08-17 17:40:49 +000033 auto handover = ConsumeRandomLengthStringAsBytesFrom(fdp);
Andrew Scull190b4382021-10-13 18:38:51 +000034
35 // Initialize output parameters with fuzz data in case they are wrongly being
36 // read from.
Andrew Scull73454b32023-08-17 17:40:49 +000037 constexpr size_t kNextHandoverBufferSize = 1024;
38 auto next_handover_actual_size = fdp.ConsumeIntegral<size_t>();
39 uint8_t next_handover[kNextHandoverBufferSize] = {};
Andrew Scull190b4382021-10-13 18:38:51 +000040
Andrew Scull73454b32023-08-17 17:40:49 +000041 fdp.ConsumeData(&next_handover, kNextHandoverBufferSize);
Andrew Scull190b4382021-10-13 18:38:51 +000042
43 // Fuzz the main flow.
Andrew Scull73454b32023-08-17 17:40:49 +000044 DiceAndroidHandoverMainFlow(
45 /*context=*/NULL, handover.data(), handover.size(), input_values,
46 kNextHandoverBufferSize, next_handover, &next_handover_actual_size);
Andrew Scull190b4382021-10-13 18:38:51 +000047
48 return 0;
49}