mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-09-25 04:09:36 +03:00
cmJSONParserFuzzer: Port to use cmJSONState
Given that most call-sites throughout CMake now use the cmJSONState wrapper instead of calling into jsoncpp directly, the fuzzing test should also now go through the wrapper.
This commit is contained in:
@@ -21,9 +21,10 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <cm3p/json/reader.h>
|
||||
#include <cm3p/json/value.h>
|
||||
|
||||
#include "cmJSONState.h"
|
||||
|
||||
// Limit input size
|
||||
static constexpr size_t kMaxInputSize = 256 * 1024; // 256KB
|
||||
|
||||
@@ -76,31 +77,28 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size)
|
||||
|
||||
std::string input(reinterpret_cast<char const*>(data), size);
|
||||
|
||||
Json::Value root;
|
||||
Json::CharReaderBuilder builder;
|
||||
std::string errors;
|
||||
{
|
||||
Json::Value root;
|
||||
std::istringstream stream(input);
|
||||
|
||||
std::istringstream stream(input);
|
||||
|
||||
// Try parsing with default settings
|
||||
bool success = Json::parseFromStream(builder, stream, &root, &errors);
|
||||
|
||||
if (success) {
|
||||
// Traverse the parsed structure
|
||||
TraverseValue(root);
|
||||
// Try parsing with default settings
|
||||
cmJSONState parseState(stream, &root, cmJSONState::StrictMode::Relaxed);
|
||||
if (!parseState.errors.empty()) {
|
||||
// Traverse the parsed structure
|
||||
TraverseValue(root);
|
||||
}
|
||||
}
|
||||
|
||||
// Also try with strict mode
|
||||
builder["strictRoot"] = true;
|
||||
builder["allowComments"] = false;
|
||||
builder["allowTrailingCommas"] = false;
|
||||
{
|
||||
Json::Value root;
|
||||
std::istringstream stream(input);
|
||||
|
||||
stream.clear();
|
||||
stream.str(input);
|
||||
|
||||
success = Json::parseFromStream(builder, stream, &root, &errors);
|
||||
if (success) {
|
||||
TraverseValue(root);
|
||||
// Also try with strict mode
|
||||
cmJSONState parseState(stream, &root, cmJSONState::StrictMode::Strict);
|
||||
if (!parseState.errors.empty()) {
|
||||
// Traverse the parsed structure
|
||||
TraverseValue(root);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user