Skip to content

Commit

Permalink
Add maximum recursion depth to read_json_value
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowNinja committed Jan 11, 2014
1 parent a9df87e commit a3586cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/script/common/c_content.cpp
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/script/common/c_content.h
Expand Up @@ -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[];

Expand Down

0 comments on commit a3586cd

Please sign in to comment.