summaryrefslogtreecommitdiffstats
path: root/chromium/base/json/json_writer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/base/json/json_writer.cc')
-rw-r--r--chromium/base/json/json_writer.cc20
1 files changed, 14 insertions, 6 deletions
diff --git a/chromium/base/json/json_writer.cc b/chromium/base/json/json_writer.cc
index 76a93b2db00..f3d2dc14911 100644
--- a/chromium/base/json/json_writer.cc
+++ b/chromium/base/json/json_writer.cc
@@ -25,19 +25,20 @@ const char kPrettyPrintLineEnding[] = "\n";
#endif
// static
-bool JSONWriter::Write(const Value& node, std::string* json) {
- return WriteWithOptions(node, 0, json);
+bool JSONWriter::Write(const Value& node, std::string* json, size_t max_depth) {
+ return WriteWithOptions(node, 0, json, max_depth);
}
// static
bool JSONWriter::WriteWithOptions(const Value& node,
int options,
- std::string* json) {
+ std::string* json,
+ size_t max_depth) {
json->clear();
// Is there a better way to estimate the size of the output?
json->reserve(1024);
- JSONWriter writer(options, json);
+ JSONWriter writer(options, json, max_depth);
bool result = writer.BuildJSONString(node, 0U);
if (options & OPTIONS_PRETTY_PRINT)
@@ -46,16 +47,23 @@ bool JSONWriter::WriteWithOptions(const Value& node,
return result;
}
-JSONWriter::JSONWriter(int options, std::string* json)
+JSONWriter::JSONWriter(int options, std::string* json, size_t max_depth)
: omit_binary_values_((options & OPTIONS_OMIT_BINARY_VALUES) != 0),
omit_double_type_preservation_(
(options & OPTIONS_OMIT_DOUBLE_TYPE_PRESERVATION) != 0),
pretty_print_((options & OPTIONS_PRETTY_PRINT) != 0),
- json_string_(json) {
+ json_string_(json),
+ max_depth_(max_depth),
+ stack_depth_(0) {
DCHECK(json);
+ CHECK_LE(max_depth, internal::kAbsoluteMaxDepth);
}
bool JSONWriter::BuildJSONString(const Value& node, size_t depth) {
+ internal::StackMarker depth_check(max_depth_, &stack_depth_);
+ if (depth_check.IsTooDeep())
+ return false;
+
switch (node.type()) {
case Value::Type::NONE:
json_string_->append("null");