forked from CrowCpp/Crow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_fuzzer.cpp
More file actions
35 lines (31 loc) · 1.06 KB
/
json_fuzzer.cpp
File metadata and controls
35 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <cstdint>
#include <string>
#include "crow/json.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size == 0) {
return 0;
}
std::string input(reinterpret_cast<const char*>(data), size);
try {
crow::json::rvalue json_val = crow::json::load(input);
if (json_val) {
// If parsing succeeded, try to access some properties to trigger more code
auto t = json_val.t();
if (t == crow::json::type::Object) {
for (const auto& key : json_val.keys()) {
auto& val = json_val[key];
(void)val.t();
}
} else if (t == crow::json::type::List) {
for (const auto& val : json_val) {
(void)val.t();
}
}
// Also try to dump it back to string
// (void)crow::json::dump(json_val); // Need to check if dump exists
}
} catch (...) {
// Ignore exceptions from invalid JSON
}
return 0;
}