do not use deprecated apis in the fuzzers (#705)

* move from deprecated interface in fuzz dump raw tape

* update fuzz_dump to the non deprecated replacement

* replace use of deprecated api

* hopefully fix windows build
This commit is contained in:
Paul Dreik 2020-04-14 07:45:30 +02:00 committed by GitHub
parent 93328c8d6d
commit 92c34f7f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 73 additions and 64 deletions

View File

@ -3,58 +3,61 @@
#include <cstdint>
#include <iostream>
#include <string>
#include <string_view>
#include "NullBuffer.h"
// from the README on the front page
void compute_dump(simdjson::ParsedJson::Iterator &pjh) {
NulOStream os;
if (pjh.is_object()) {
os << "{";
if (pjh.down()) {
pjh.print(os); // must be a string
os << ":";
pjh.next();
compute_dump(pjh); // let us recurse
while (pjh.next()) {
os << ",";
pjh.print(os);
os << ":";
pjh.next();
compute_dump(pjh); // let us recurse
}
pjh.up();
// example from doc/basics.md#tree-walking-and-json-element-types
static void print_json(std::ostream& os, simdjson::dom::element element) {
const char endl='\n';
switch (element.type()) {
case simdjson::dom::element_type::ARRAY:
os << "[";
for (simdjson::dom::element child : simdjson::dom::array(element)) {
print_json(os, child);
os << ",";
}
os << "]";
break;
case simdjson::dom::element_type::OBJECT:
os << "{";
for (simdjson::dom::key_value_pair field : simdjson::dom::object(element)) {
os << "\"" << field.key << "\": ";
print_json(os, field.value);
}
os << "}";
break;
case simdjson::dom::element_type::INT64:
os << int64_t(element) << endl;
break;
case simdjson::dom::element_type::UINT64:
os << uint64_t(element) << endl;
break;
case simdjson::dom::element_type::DOUBLE:
os << double(element) << endl;
break;
case simdjson::dom::element_type::STRING:
os << std::string_view(element) << endl;
break;
case simdjson::dom::element_type::BOOL:
os << bool(element) << endl;
break;
case simdjson::dom::element_type::NULL_VALUE:
os << "null" << endl;
break;
}
os << "}";
} else if (pjh.is_array()) {
os << "[";
if (pjh.down()) {
compute_dump(pjh); // let us recurse
while (pjh.next()) {
os << ",";
compute_dump(pjh); // let us recurse
}
pjh.up();
}
os << "]";
} else {
pjh.print(os); // just print the lone value
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
try {
auto pj = simdjson::build_parsed_json(Data, Size);
if (!pj.is_valid()) {
throw 1;
try {
simdjson::dom::parser pj;
auto elem=pj.parse(Data, Size);
auto v=elem.value();
NulOStream os;
//std::ostream& os(std::cout);
print_json(os,v);
} catch (...) {
}
simdjson::ParsedJson::Iterator pjh(pj);
if (pjh.is_ok()) {
compute_dump(pjh);
}
} catch (...) {
}
return 0;
return 0;
}

View File

@ -8,11 +8,13 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
try {
auto pj = simdjson::build_parsed_json(Data, Size);
NulOStream os;
UNUSED bool ignored=pj.dump_raw_tape(os);
} catch (...) {
}
return 0;
try {
simdjson::dom::parser pj;
auto elem=pj.parse(Data, Size);
auto v=elem.value();
NulOStream os;
UNUSED auto dumpstatus=v.dump_raw_tape(os);
} catch (...) {
}
return 0;
}

View File

@ -4,7 +4,11 @@
#include <string>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
auto ignored = simdjson::build_parsed_json(Data, Size);
return 0;
try {
simdjson::dom::parser pj;
auto result=pj.parse(Data, Size);
UNUSED auto v=result.value();
}catch(...) {
}
return 0;
}

View File

@ -8,12 +8,12 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
try {
auto pj = simdjson::build_parsed_json(Data, Size);
NulOStream os;
bool ignored=pj.print_json(os);
(void)ignored;
} catch (...) {
}
return 0;
try {
simdjson::dom::parser pj;
auto elem=pj.parse(Data, Size);
NulOStream os;
os<<elem;
} catch (...) {
}
return 0;
}