mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-06 17:45:22 +00:00
json: Configure rapidjson to use iterative parsing (#5893)
This commit is contained in:
parent
0bf2245396
commit
15d522f447
@ -19,6 +19,14 @@
|
||||
#pragma warning(disable : 4715)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This protects parsing from overflowing the stack.
|
||||
* See http://rapidjson.org/md_doc_features.html for more details.
|
||||
*
|
||||
* This must be defined before including RapidJSON headers.
|
||||
*/
|
||||
#define RAPIDJSON_PARSE_DEFAULT_FLAGS (kParseIterativeFlag)
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
#include <rapidjson/error/en.h>
|
||||
#include <rapidjson/stringbuffer.h>
|
||||
|
@ -228,4 +228,17 @@ TEST_F(ConversionsTests, test_json_bool_like) {
|
||||
EXPECT_FALSE(JSON::valueToBool(doc.doc()["false6"]));
|
||||
}
|
||||
|
||||
/*
|
||||
* By default, rapidjson will use recursive parsing without stack guards,
|
||||
* which would result in a segfault for this test. To guard against
|
||||
* malicious json, we should be configured to use iterative mode.
|
||||
* https://github.com/Tencent/rapidjson/issues/632
|
||||
*/
|
||||
TEST_F(ConversionsTests, test_iterativeparsing) {
|
||||
std::string json(543210, '[');
|
||||
auto doc = JSON::newObject();
|
||||
|
||||
EXPECT_FALSE(doc.fromString(json).ok());
|
||||
}
|
||||
|
||||
} // namespace osquery
|
||||
|
Loading…
Reference in New Issue
Block a user