-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from msm-/afl-fuzz
add support for afl-fuzz testing
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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,42 @@ | ||
/* | ||
__ _____ _____ _____ | ||
__| | __| | | | JSON for Modern C++ (fuzz test support) | ||
| | |__ | | | | | | version 2.0.0 | ||
|_____|_____|_____|_|___| https://github.com/nlohmann/json | ||
To run under afl: | ||
afl-fuzz -i testcases -o output ./fuzz | ||
Licensed under the MIT License <http://opensource.org/licenses/MIT>. | ||
*/ | ||
|
||
#include <json.hpp> | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
json *jp; | ||
|
||
#ifdef __AFL_HAVE_MANUAL_CONTROL | ||
while (__AFL_LOOP(1000)) { | ||
#endif | ||
jp = new json(); | ||
json j = *jp; | ||
try { | ||
j << std::cin; | ||
} catch (std::invalid_argument e) { | ||
std::cout << "Invalid argument in parsing" << e.what() << '\n'; | ||
} | ||
|
||
if (j.find("foo") != j.end()) { | ||
std::cout << "Found a foo"; | ||
} | ||
|
||
std::cout << j.type() << j << std::endl; | ||
|
||
delete jp; | ||
#ifdef __AFL_HAVE_MANUAL_CONTROL | ||
} | ||
#endif | ||
} |