Skip to content

Commit

Permalink
Addressed some VS code analysis warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Nov 14, 2024
1 parent 86f9e21 commit 9e6db17
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 51 deletions.
1 change: 0 additions & 1 deletion include/jsoncons/json_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ namespace jsoncons {
: basic_json_reader(std::forward<Sourceable>(source),
default_visitor_,
options,
options.err_handler(),
temp_alloc)
{
}
Expand Down
6 changes: 4 additions & 2 deletions include/jsoncons_ext/jsonschema/common/keyword_validators.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ namespace jsonschema {

public:
recursive_ref_validator(const Json& schema, const uri& schema_location)
: keyword_validator_base<Json>("$recursiveRef", schema, schema_location)
: keyword_validator_base<Json>("$recursiveRef", schema, schema_location),
tentative_target_(nullptr)
{}

uri get_base_uri() const
Expand Down Expand Up @@ -136,7 +137,8 @@ namespace jsonschema {

public:
dynamic_ref_validator(const Json& schema, const uri& schema_location, const uri_wrapper& value)
: keyword_validator_base<Json>("$dynamicRef", schema, schema_location), value_(value)
: keyword_validator_base<Json>("$dynamicRef", schema, schema_location), value_(value),
tentative_target_(nullptr)
{
//std::cout << "dynamic_ref_validator path: " << schema_location.string() << ", value: " << value.string() << "\n";
}
Expand Down
8 changes: 4 additions & 4 deletions test/corelib/src/JSONTestSuite_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ TEST_CASE("JSON Parsing Test Suite")
if (fs::exists(p) && fs::is_regular_file(p) && p.path().extension() == ".json" && p.path().filename().c_str()[0] == 'y')
{
std::ifstream is(p.path().c_str());
strict_json_parsing err_handler;
json_stream_reader reader(is, err_handler);
auto options = json_options{}.err_handler(strict_json_parsing{});
json_stream_reader reader(is, options);
std::error_code ec;
reader.read(ec);
if (ec)
Expand All @@ -53,8 +53,8 @@ TEST_CASE("JSON Parsing Test Suite")
if (fs::exists(p) && fs::is_regular_file(p) && p.path().extension() == ".json" && p.path().filename().c_str()[0] == 'n')
{
std::ifstream is(p.path().c_str());
strict_json_parsing err_handler;
json_stream_reader reader(is, err_handler);
auto options = json_options{}.err_handler(strict_json_parsing{});
json_stream_reader reader(is, options);
std::error_code ec;
reader.read(ec);
if (!ec)
Expand Down
Binary file not shown.
Binary file not shown.
136 changes: 92 additions & 44 deletions test/fuzz_regression/src/fuzz_regression_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using namespace jsoncons;

#if 0
TEST_CASE("oss-fuzz issues")
{
// Fuzz target: fuzz_parse
Expand Down Expand Up @@ -276,32 +277,6 @@ TEST_CASE("oss-fuzz issues")
CHECK(ec == bson::bson_errc::unexpected_eof);
}

// Fuzz target: fuzz_cbor_encoder
// Issue: failed_throw
// Resolution: change assert to illegal_chunked_string error code
SECTION("issue 21902")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-fuzz_cbor_encoder-5665976638242816";

std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521

try
{
std::vector<uint8_t> buf;
cbor::cbor_bytes_encoder encoder(buf);
cbor::cbor_stream_reader reader(is, encoder);

std::error_code ec;
REQUIRE_NOTHROW(reader.read(ec));
CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521
}
catch (const std::exception& e)
{
std::cout << e.what() << "" << std::endl;
}
}

// Fuzz target: fuzz_csv_encoder
// Issue: Failed throw
// Resolution: check if csv_parser is still in start state when no more input
Expand Down Expand Up @@ -507,24 +482,6 @@ TEST_CASE("oss-fuzz issues")
reader.read(ec);
}

// Fuzz target: fuzz_ubjson_encoder
// Issue: Timeout
SECTION("issue 23840")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-5711604342849536";

std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521

std::vector<uint8_t> output;
ubjson::ubjson_bytes_encoder encoder(output);
ubjson::ubjson_stream_reader reader(is, encoder);

std::error_code ec;
reader.read(ec);
CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521
}

// Fuzz target: fuzz_ubjson
// Issue: failed_throw
SECTION("issue 25891")
Expand Down Expand Up @@ -704,4 +661,95 @@ TEST_CASE("oss-fuzz issues")
}
}
}
#endif

TEST_CASE("Fuzz target: fuzz_ubjson_encoder")
{
// Issue: Timeout
/*SECTION("issue 23840")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-5711604342849536";
std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521
std::vector<uint8_t> output;
ubjson::ubjson_bytes_encoder encoder(output);
ubjson::ubjson_stream_reader reader(is, encoder);
std::error_code ec;
reader.read(ec);
CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521
}*/

// Issue: Timeout (exceeds 60 secs)
/*SECTION("issue 378891965")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_ubjson_encoder-6542820946542592";
std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521
std::vector<uint8_t> output;
ubjson::ubjson_bytes_encoder encoder(output);
ubjson::ubjson_stream_reader reader(is, encoder);
std::error_code ec;
reader.read(ec);
CHECK(ec == ubjson::ubjson_errc::unknown_type); //-V521
}*/
}

TEST_CASE("Fuzz target: fuzz_cbor_encoder")
{
// Fuzz target: fuzz_cbor_encoder
// Issue: failed_throw
// Resolution: change assert to illegal_chunked_string error code
/* SECTION("issue 21902")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-fuzz_cbor_encoder-5665976638242816";
std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521
try
{
std::vector<uint8_t> buf;
cbor::cbor_bytes_encoder encoder(buf);
cbor::cbor_stream_reader reader(is, encoder);
std::error_code ec;
REQUIRE_NOTHROW(reader.read(ec));
CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521
}
catch (const std::exception& e)
{
std::cout << e.what() << "" << std::endl;
}
}
*/
// Fuzz target: fuzz_cbor_encoder
// Issue: Integer-overflow
SECTION("issue 42538003")
{
std::string pathname = "fuzz_regression/input/clusterfuzz-testcase-minimized-fuzz_cbor_encoder-4729089884225536";

std::ifstream is(pathname, std::ios_base::in | std::ios_base::binary);
CHECK(is); //-V521

try
{
std::vector<uint8_t> buf;
cbor::cbor_bytes_encoder encoder(buf);
cbor::cbor_stream_reader reader(is, encoder);

std::error_code ec;
REQUIRE_NOTHROW(reader.read(ec));
CHECK(ec == cbor::cbor_errc::illegal_chunked_string); //-V521
}
catch (const std::exception& e)
{
std::cout << e.what() << "" << std::endl;
}
}
}

0 comments on commit 9e6db17

Please sign in to comment.