1*635a8641SAndroid Build Coastguard Worker // Copyright 2015 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker
5*635a8641SAndroid Build Coastguard Worker #include "base/json/json_reader.h"
6*635a8641SAndroid Build Coastguard Worker #include "base/values.h"
7*635a8641SAndroid Build Coastguard Worker
8*635a8641SAndroid Build Coastguard Worker // Entry point for LibFuzzer.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)9*635a8641SAndroid Build Coastguard Worker extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
10*635a8641SAndroid Build Coastguard Worker if (size < 2)
11*635a8641SAndroid Build Coastguard Worker return 0;
12*635a8641SAndroid Build Coastguard Worker
13*635a8641SAndroid Build Coastguard Worker // Create a copy of input buffer, as otherwise we don't catch
14*635a8641SAndroid Build Coastguard Worker // overflow that touches the last byte (which is used in options).
15*635a8641SAndroid Build Coastguard Worker std::unique_ptr<char[]> input(new char[size - 1]);
16*635a8641SAndroid Build Coastguard Worker memcpy(input.get(), data, size - 1);
17*635a8641SAndroid Build Coastguard Worker
18*635a8641SAndroid Build Coastguard Worker base::StringPiece input_string(input.get(), size - 1);
19*635a8641SAndroid Build Coastguard Worker
20*635a8641SAndroid Build Coastguard Worker const int options = data[size - 1];
21*635a8641SAndroid Build Coastguard Worker
22*635a8641SAndroid Build Coastguard Worker int error_code, error_line, error_column;
23*635a8641SAndroid Build Coastguard Worker std::string error_message;
24*635a8641SAndroid Build Coastguard Worker base::JSONReader::ReadAndReturnError(input_string, options, &error_code,
25*635a8641SAndroid Build Coastguard Worker &error_message, &error_line,
26*635a8641SAndroid Build Coastguard Worker &error_column);
27*635a8641SAndroid Build Coastguard Worker
28*635a8641SAndroid Build Coastguard Worker return 0;
29*635a8641SAndroid Build Coastguard Worker }
30