Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
|
danakj
2016/10/28 01:50:56
2016
aizatsky
2016/10/31 19:56:18
done
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // A fuzzer that checks correctness of json parser/writer. | |
| 6 // The fuzzer input is passed through parsing twice, | |
| 7 // so that presumably valdid json is parsed/written again. | |
|
danakj
2016/10/28 01:50:56
valid
aizatsky
2016/10/31 19:56:18
done
| |
| 8 | |
| 9 #include <stddef.h> | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 #include <string> | |
| 13 | |
| 14 #include "base/json/json_reader.h" | |
| 15 #include "base/json/json_writer.h" | |
| 16 #include "base/json/string_escape.h" | |
| 17 #include "base/logging.h" | |
| 18 #include "base/values.h" | |
| 19 | |
| 20 // Entry point for LibFuzzer. | |
| 21 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
| 22 if (size < 1) | |
|
danakj
2016/10/28 01:50:56
if (!size) is the usual way to write this, but don
aizatsky
2016/10/31 19:56:18
done. Agree, less than 2 bytes is pointless.
| |
| 23 return 0; | |
| 24 | |
| 25 int error_code, error_line, error_column; | |
| 26 std::string error_message; | |
| 27 | |
| 28 const std::string input_string(reinterpret_cast<const char*>(data), size - 1); | |
| 29 const int options = data[size - 1]; | |
|
danakj
2016/10/28 01:50:56
Where is this format documented?
aizatsky
2016/10/31 19:56:18
It is not. It is each fuzzer's decision on how to
| |
| 30 auto input_value = base::JSONReader::ReadAndReturnError( | |
|
danakj
2016/10/28 01:50:56
parsed_value?
aizatsky
2016/10/31 19:56:18
done
| |
| 31 input_string, options, &error_code, &error_message, &error_line, | |
| 32 &error_column); | |
| 33 if (!input_value) | |
| 34 return 0; | |
| 35 | |
| 36 std::string output1; | |
|
danakj
2016/10/28 01:50:56
parsed_output?
aizatsky
2016/10/31 19:56:18
done
| |
| 37 bool b = base::JSONWriter::Write(*input_value, &output1); | |
| 38 LOG_ASSERT(b); | |
| 39 | |
| 40 auto value2 = base::JSONReader::ReadAndReturnError( | |
|
danakj
2016/10/28 01:50:56
double_parsed_value?
aizatsky
2016/10/31 19:56:18
done
| |
| 41 output1, options, &error_code, &error_message, &error_line, | |
| 42 &error_column); | |
| 43 LOG_ASSERT(value2); | |
| 44 std::string output2; | |
|
danakj
2016/10/28 01:50:56
double_parsed_output?
using numbers to distinguis
aizatsky
2016/10/31 19:56:18
done
| |
| 45 bool b2 = base::JSONWriter::Write(*value2, &output2); | |
| 46 LOG_ASSERT(b2); | |
| 47 | |
| 48 LOG_ASSERT(output1 == output2) << "Parser/Writer mismatch." | |
| 49 "\nInput=" << base::GetQuotedJSONString(output1) << | |
| 50 "\nOutput=" << base::GetQuotedJSONString(output2); | |
| 51 | |
| 52 return 0; | |
| 53 } | |
| OLD | NEW |