-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add a simple fuzz test for jsoncpp. #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
baylesj
merged 26 commits into
open-source-parsers:master
from
Google-Autofuzz:add_autofuzz_fuzzer
Jun 27, 2019
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
38dd623
Add a simple fuzz test for jsoncpp.
Google-Autofuzz 6cbae34
Updated header and fixed the bug
Google-Autofuzz 3f5b2ec
Updated fuzz.h
Google-Autofuzz 0ac1ef1
Update fuzz.cpp
Google-Autofuzz 882a0b0
Update fuzz.h
Google-Autofuzz e297668
Update fuzz.h
Google-Autofuzz 54f5ef4
Update fuzz.cpp
Google-Autofuzz 95b1aee
Update fuzz.h
Google-Autofuzz b09f814
Update fuzz.cpp
Google-Autofuzz c45134d
Update fuzz.h
Google-Autofuzz 2884e69
Update fuzz.cpp
Google-Autofuzz 5972b88
fix llvm
Google-Autofuzz 43ce3c7
added llvm
Google-Autofuzz a778bbe
Added include fuzz.cpp
Google-Autofuzz 9f0cd22
Update main.cpp
Google-Autofuzz 73cf116
Update main.cpp
Google-Autofuzz ebc2047
Update main.cpp
Google-Autofuzz a845c63
Update CMakeLists.txt
Google-Autofuzz 7101a85
Update CMakeLists.txt
Google-Autofuzz d715e73
Update jsontest.cpp
Google-Autofuzz aca048c
Update jsontest.cpp
Google-Autofuzz a32b530
Update jsontest.cpp
Google-Autofuzz 7b3f027
added fuzz.cpp to macro in main.cpp
Google-Autofuzz fe99a87
Merge branch 'add_autofuzz_fuzzer' of https://github.com/Google-Autof…
Google-Autofuzz e16638a
Update main.cpp
Google-Autofuzz 0a35653
Add fuzz.cpp to jsoncpp_test
Google-Autofuzz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
add_executable( jsoncpp_test | ||
jsontest.cpp | ||
jsontest.h | ||
fuzz.cpp | ||
fuzz.h | ||
main.cpp | ||
) | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2007-2019 The JsonCpp Authors | ||
// Distributed under MIT license, or public domain if desired and | ||
// recognized in your jurisdiction. | ||
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE | ||
|
||
#include "fuzz.h" | ||
|
||
#include <cstdint> | ||
#include <json/config.h> | ||
#include <json/json.h> | ||
#include <memory> | ||
#include <stdint.h> | ||
#include <string> | ||
|
||
namespace Json { | ||
class Exception; | ||
} | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | ||
Json::CharReaderBuilder builder; | ||
|
||
if (size < sizeof(uint32_t)) { | ||
return 0; | ||
} | ||
|
||
uint32_t hash_settings = *(const uint32_t*)data; | ||
data += sizeof(uint32_t); | ||
|
||
builder.settings_["failIfExtra"] = hash_settings & (1 << 0); | ||
builder.settings_["allowComments_"] = hash_settings & (1 << 1); | ||
builder.settings_["strictRoot_"] = hash_settings & (1 << 2); | ||
builder.settings_["allowDroppedNullPlaceholders_"] = hash_settings & (1 << 3); | ||
builder.settings_["allowNumericKeys_"] = hash_settings & (1 << 4); | ||
builder.settings_["allowSingleQuotes_"] = hash_settings & (1 << 5); | ||
builder.settings_["failIfExtra_"] = hash_settings & (1 << 6); | ||
builder.settings_["rejectDupKeys_"] = hash_settings & (1 << 7); | ||
builder.settings_["allowSpecialFloats_"] = hash_settings & (1 << 8); | ||
|
||
std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); | ||
|
||
Json::Value root; | ||
const char* data_str = reinterpret_cast<const char*>(data); | ||
try { | ||
reader->parse(data_str, data_str + size, &root, nullptr); | ||
} catch (Json::Exception const&) { | ||
} | ||
// Whether it succeeded or not doesn't matter. | ||
return 0; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright 2007-2010 The JsonCpp Authors | ||
// Distributed under MIT license, or public domain if desired and | ||
// recognized in your jurisdiction. | ||
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE | ||
|
||
#ifndef FUZZ_H_INCLUDED | ||
#define FUZZ_H_INCLUDED | ||
|
||
#include <cstddef> | ||
#include <stdint.h> | ||
|
||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size); | ||
Google-Autofuzz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#endif // ifndef FUZZ_H_INCLUDED |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.