webmcp
changeset 445:8145293e3f4a
Do not use luaL_addchar unless Lua string buffer is on top of stack (possible segmentation fault)
author | jbe |
---|---|
date | Mon May 16 15:41:58 2016 +0200 (2016-05-16) |
parents | 5d307886bd89 |
children | 0221836a9db5 |
files | libraries/json/json.c |
line diff
1.1 --- a/libraries/json/json.c Sun Feb 28 19:16:03 2016 +0100 1.2 +++ b/libraries/json/json.c Mon May 16 15:41:58 2016 +0200 1.3 @@ -1312,14 +1312,14 @@ 1.4 case JSON_TABLETYPE_OBJECT: 1.5 // finish iteration if all string keys have been processed: 1.6 if (container->pos == container->count) goto json_export_close; 1.7 - // push current string key on top of stack: 1.8 - key = &container->keys[container->pos]; 1.9 - lua_pushlstring(L, key->data, key->length); 1.10 // check if the key has already been exported: 1.11 if (!containerkey) { 1.12 // if no, 1.13 // add a comma to the output buffer if necessary: 1.14 if (container->pos) luaL_addchar(&buf, ','); 1.15 + // push current string key on top of stack: 1.16 + key = &container->keys[container->pos]; 1.17 + lua_pushlstring(L, key->data, key->length); 1.18 // set containerkey variable to true: 1.19 containerkey = 1; 1.20 } else { 1.21 @@ -1328,6 +1328,9 @@ 1.22 luaL_addchar(&buf, ':'); 1.23 // add a space to the output buffer for pretty results: 1.24 if (pretty) luaL_addchar(&buf, ' '); 1.25 + // push current string key on top of stack: 1.26 + key = &container->keys[container->pos]; 1.27 + lua_pushlstring(L, key->data, key->length); 1.28 // replace string key on top of stack with corresponding value: 1.29 lua_rawget(L, json_export_luacontainer_idx); 1.30 // reset containerkey variable