beached / daw_json_link

Fast, convenient JSON serialization and parsing in C++
https://beached.github.io/daw_json_link/
Boost Software License 1.0
475 stars 31 forks source link

Json Value parsing can produce segmentation faults #398

Closed MartinTheDragon closed 1 year ago

MartinTheDragon commented 1 year ago

Trying to parse non-existing paths as strings will cause segmentation faults.

Example:

using namespace daw::json;
using std::string;

json_value json{R"({"food":"lasagna"})"};
string& favourite_food = as<string>(json["garfield"]); // SEGFAULT

Attempting to parse number literals in a similar manner will produce a json_exception with ErrorReason::UnexpectedEndOfData as the specified reason, which may or may not be correct.

beached commented 1 year ago

There was an issue here, but also, if the value doesn't exist it should throw. daw::json::as<std::optional<std::string>>( json ) would be correct or some other Nullable type.

beached commented 1 year ago

Thanks for finding, this is closed by #400