# HG changeset patch # User jbe # Date 1463406118 -7200 # Node ID 8145293e3f4a9fd3fadaa2fd57633277646e2660 # Parent 5d307886bd89d18ac8f5442f34038873235602b0 Do not use luaL_addchar unless Lua string buffer is on top of stack (possible segmentation fault) diff -r 5d307886bd89 -r 8145293e3f4a libraries/json/json.c --- a/libraries/json/json.c Sun Feb 28 19:16:03 2016 +0100 +++ b/libraries/json/json.c Mon May 16 15:41:58 2016 +0200 @@ -1312,14 +1312,14 @@ case JSON_TABLETYPE_OBJECT: // finish iteration if all string keys have been processed: if (container->pos == container->count) goto json_export_close; - // push current string key on top of stack: - key = &container->keys[container->pos]; - lua_pushlstring(L, key->data, key->length); // check if the key has already been exported: if (!containerkey) { // if no, // add a comma to the output buffer if necessary: if (container->pos) luaL_addchar(&buf, ','); + // push current string key on top of stack: + key = &container->keys[container->pos]; + lua_pushlstring(L, key->data, key->length); // set containerkey variable to true: containerkey = 1; } else { @@ -1328,6 +1328,9 @@ luaL_addchar(&buf, ':'); // add a space to the output buffer for pretty results: if (pretty) luaL_addchar(&buf, ' '); + // push current string key on top of stack: + key = &container->keys[container->pos]; + lua_pushlstring(L, key->data, key->length); // replace string key on top of stack with corresponding value: lua_rawget(L, json_export_luacontainer_idx); // reset containerkey variable