summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2014-01-11 14:08:02 -0500
committerShadowNinja <shadowninja@minetest.net>2014-01-11 14:08:02 -0500
commita3586cd18d5a6182a578dc08a6dbc23e16df4c14 (patch)
treec0f0a0715086912b5f9b99edc85dedca4866fcf3 /src
parenta9df87ede06f8f0f69e3481cf58f6d59d3f9ebbf (diff)
downloadminetest-a3586cd18d5a6182a578dc08a6dbc23e16df4c14.tar.gz
minetest-a3586cd18d5a6182a578dc08a6dbc23e16df4c14.tar.bz2
minetest-a3586cd18d5a6182a578dc08a6dbc23e16df4c14.zip
Add maximum recursion depth to read_json_value
Diffstat (limited to 'src')
-rw-r--r--src/script/common/c_content.cpp7
-rw-r--r--src/script/common/c_content.h3
2 files changed, 7 insertions, 3 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 962391a04..c4acb7c32 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -1088,8 +1088,11 @@ bool push_json_value(lua_State *L, const Json::Value &value, int nullindex)
}
// Converts Lua table --> JSON
-void read_json_value(lua_State *L, Json::Value &root, int index)
+void read_json_value(lua_State *L, Json::Value &root, int index, u8 recursion)
{
+ if (recursion > 16) {
+ throw SerializationError("Maximum recursion depth exceeded");
+ }
int type = lua_type(L, index);
if (type == LUA_TBOOLEAN) {
root = (bool) lua_toboolean(L, index);
@@ -1104,7 +1107,7 @@ void read_json_value(lua_State *L, Json::Value &root, int index)
while (lua_next(L, index)) {
// Key is at -2 and value is at -1
Json::Value value;
- read_json_value(L, value, lua_gettop(L));
+ read_json_value(L, value, lua_gettop(L), recursion + 1);
Json::ValueType roottype = root.type();
int keytype = lua_type(L, -1);
diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h
index c2d84ac11..163e803db 100644
--- a/src/script/common/c_content.h
+++ b/src/script/common/c_content.h
@@ -152,7 +152,8 @@ bool push_json_value (lua_State *L,
int nullindex);
void read_json_value (lua_State *L,
Json::Value &root,
- int index);
+ int index,
+ u8 recursion = 0);
extern struct EnumString es_TileAnimationType[];