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