aboutsummaryrefslogtreecommitdiff
path: root/include/flatbuffers/idl.h
diff options
context:
space:
mode:
authorVladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com>2018-10-04 23:27:37 +0700
committerWouter van Oortmerssen <aardappel@gmail.com>2018-10-04 09:27:37 -0700
commit925c1d77fcc72636924c3c13428a34180c30f96f (patch)
treef8877e796a1fb7c1f9d4f6983cf0df1e80878b22 /include/flatbuffers/idl.h
parentc0698cc33f1e534bb59c455909b88cc2726089af (diff)
downloadflatbuffers-925c1d77fcc72636924c3c13428a34180c30f96f.tar.gz
Fix recursion counter check. Add control to override depth of nested … (#4953)
* Fix recursion counter check. Add control to override depth of nested objects. * Change if-condition to `>=`
Diffstat (limited to 'include/flatbuffers/idl.h')
-rw-r--r--include/flatbuffers/idl.h11
1 files changed, 9 insertions, 2 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 63446247..cf5446a2 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -34,6 +34,12 @@
// This file defines the data types representing a parsed IDL (Interface
// Definition Language) / schema file.
+// Limits maximum depth of nested objects.
+// Prevents stack overflow while parse flatbuffers or json.
+#if !defined(FLATBUFFERS_MAX_PARSING_DEPTH)
+# define FLATBUFFERS_MAX_PARSING_DEPTH 64
+#endif
+
namespace flatbuffers {
// The order of these matters for Is*() functions below.
@@ -745,10 +751,11 @@ class Parser : public ParserState {
bool SupportsVectorOfUnions() const;
Namespace *UniqueNamespace(Namespace *ns);
- enum { kMaxParsingDepth = 64 };
FLATBUFFERS_CHECKED_ERROR RecurseError();
template<typename F> CheckedError Recurse(F f) {
- if (++recurse_protection_counter >= kMaxParsingDepth) return RecurseError();
+ if (recurse_protection_counter >= (FLATBUFFERS_MAX_PARSING_DEPTH))
+ return RecurseError();
+ recurse_protection_counter++;
auto ce = f();
recurse_protection_counter--;
return ce;