aboutsummaryrefslogtreecommitdiff
path: root/src/univalue/lib/univalue_read.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2020-02-09 07:44:12 -0800
committerMarcoFalke <falke.marco@gmail.com>2020-02-09 07:44:29 -0800
commitfad9ea8fdb0a7269a3fcc472fd948669d74f7aa7 (patch)
tree570aeb93521ebf211471ef6d2e77391be5034f8a /src/univalue/lib/univalue_read.cpp
parent75fb37ce68289eb7e00e2ccdd2ef7f9271332545 (diff)
parent97aa5740c0e9ef433cbedafe689b641297b50f5e (diff)
Update univalue subtree
Diffstat (limited to 'src/univalue/lib/univalue_read.cpp')
-rw-r--r--src/univalue/lib/univalue_read.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/univalue/lib/univalue_read.cpp b/src/univalue/lib/univalue_read.cpp
index 14834db24d..5c6a1acf75 100644
--- a/src/univalue/lib/univalue_read.cpp
+++ b/src/univalue/lib/univalue_read.cpp
@@ -8,6 +8,14 @@
#include "univalue.h"
#include "univalue_utffilter.h"
+/*
+ * According to stackexchange, the original json test suite wanted
+ * to limit depth to 22. Widely-deployed PHP bails at depth 512,
+ * so we will follow PHP's lead, which should be more than sufficient
+ * (further stackexchange comments indicate depth > 32 rarely occurs).
+ */
+static const size_t MAX_JSON_DEPTH = 512;
+
static bool json_isdigit(int ch)
{
return ((ch >= '0') && (ch <= '9'));
@@ -323,6 +331,9 @@ bool UniValue::read(const char *raw, size_t size)
stack.push_back(newTop);
}
+ if (stack.size() > MAX_JSON_DEPTH)
+ return false;
+
if (utyp == VOBJ)
setExpect(OBJ_NAME);
else