diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-18 00:55:33 +1030 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 18:54:35 +1030 |
commit | 0c6f2e488e17528ae42481d09879fd36551000e9 (patch) | |
tree | aa12aab7e8619df8235eccb2c46368d822d45c33 /lua_cjson.c | |
parent | 8faf8490e518315a8eff17a76b019debe48104b4 (diff) | |
download | lua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.tar.gz lua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.tar.bz2 lua-cjson-0c6f2e488e17528ae42481d09879fd36551000e9.zip |
Add depth/index to decode depth error message
Include depth and character index when throwing decode nesting errors.
Pre-emptively add a test decoding a massively nested JSON array. Lua
stack overflow faults are unlikely to occur on simple data structures.
Valgrind can highlight stack allocation bugs with complicated JSON even
if the test succeeds.
Diffstat (limited to 'lua_cjson.c')
-rw-r--r-- | lua_cjson.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 4a2ce0f..b64ed62 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -1034,7 +1034,7 @@ static void json_next_number_token(json_parse_t *json, json_token_t *token) | |||
1034 | */ | 1034 | */ |
1035 | static void json_next_token(json_parse_t *json, json_token_t *token) | 1035 | static void json_next_token(json_parse_t *json, json_token_t *token) |
1036 | { | 1036 | { |
1037 | json_token_type_t *ch2token = json->cfg->ch2token; | 1037 | const json_token_type_t *ch2token = json->cfg->ch2token; |
1038 | int ch; | 1038 | int ch; |
1039 | 1039 | ||
1040 | /* Eat whitespace. */ | 1040 | /* Eat whitespace. */ |
@@ -1149,7 +1149,8 @@ static void json_decode_descend(lua_State *l, json_parse_t *json, int slots) | |||
1149 | } | 1149 | } |
1150 | 1150 | ||
1151 | strbuf_free(json->tmp); | 1151 | strbuf_free(json->tmp); |
1152 | luaL_error(l, "Too many nested data structures"); | 1152 | luaL_error(l, "Found too many nested data structures (%d) at character %d", |
1153 | json->current_depth, json->ptr - json->data); | ||
1153 | } | 1154 | } |
1154 | 1155 | ||
1155 | static void json_parse_object_context(lua_State *l, json_parse_t *json) | 1156 | static void json_parse_object_context(lua_State *l, json_parse_t *json) |