mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
Fix undefined-behavior in copyValueFromJValue
Issue highlighted by asan activated in PR osquery/osquery#5628 Imprecisions between float -> double -> json -> double -> float lead to out of range values been saved into a float variable. Since json has only the notion of doubles as floating point numbers, it's better to require to use them. Also forced the json parser to parse floating point numbers with full precision, otherwise the test testing for precision would fail. PR: osquery/osquery#5665
This commit is contained in:
parent
0a302cd08e
commit
ea17c51bb8
@ -73,7 +73,7 @@ Expected<std::string, JsonError> toJson(Type const& value) {
|
||||
template <typename Type, typename RapidJsonInStream>
|
||||
ExpectedSuccess<JsonError> fromJson(Type& value, RapidJsonInStream& is) {
|
||||
auto dom = rapidjson::Document{};
|
||||
dom.ParseStream(is);
|
||||
dom.ParseStream<rapidjson::kParseFullPrecisionFlag>(is);
|
||||
if (dom.HasParseError()) {
|
||||
return createError(JsonError::Syntax)
|
||||
<< "Can not parse value of type "
|
||||
|
@ -174,7 +174,7 @@ class JsonReader final {
|
||||
|
||||
template <typename KeyType,
|
||||
typename ValueType,
|
||||
typename std::enable_if<std::is_floating_point<ValueType>::value,
|
||||
typename std::enable_if<std::is_same<ValueType, double>::value,
|
||||
int>::type = 0>
|
||||
void copyValueFromJValue(const KeyType& key,
|
||||
ValueType& value,
|
||||
|
@ -97,7 +97,7 @@ class SecondTestClass {
|
||||
return second_;
|
||||
}
|
||||
|
||||
float const& getThird() const {
|
||||
double const& getThird() const {
|
||||
return third_;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ class SecondTestClass {
|
||||
private:
|
||||
std::string first_ = __FILE__;
|
||||
int second_ = __LINE__;
|
||||
float third_ = -1;
|
||||
double third_ = -1;
|
||||
bool fourth_ = false;
|
||||
};
|
||||
|
||||
@ -189,7 +189,7 @@ struct ThirdTestClass {
|
||||
|
||||
std::string first = "";
|
||||
unsigned second = 0u;
|
||||
float third = 0.;
|
||||
double third = 0.;
|
||||
std::int64_t fourth = 0;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user