0003-luci-lib-jsonc-Ignore-non-string-or-number-keys-in-tables.patch 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. From: Jan-Philipp Litza <janphilipp@litza.de>
  2. Date: Sun, 30 Aug 2015 15:42:52 +0200
  3. Subject: luci-lib-jsonc: Ignore non-string-or-number keys in tables
  4. Previously, the following caused a segmentation fault:
  5. json.stringify({[{}] = true})
  6. This was caused by lua_tostring() returning NULL for anything but
  7. strings and numbers, letting json_object_object_add crash.
  8. This patch makes jsonc ignore all keys which have no string
  9. representation altogether.
  10. Signed-off-by: Jan-Philipp Litza <janphilipp@litza.de>
  11. diff --git a/libs/luci-lib-jsonc/src/jsonc.c b/libs/luci-lib-jsonc/src/jsonc.c
  12. index 49cb21f5bcb2817792d0eef8dc5cd567bc6d86bc..827fde8843082e956b0c89b5855feeabd790e880 100644
  13. --- a/libs/luci-lib-jsonc/src/jsonc.c
  14. +++ b/libs/luci-lib-jsonc/src/jsonc.c
  15. @@ -286,8 +286,9 @@ static struct json_object * _lua_to_json(lua_State *L, int index)
  16. lua_pushvalue(L, -2);
  17. key = lua_tostring(L, -1);
  18. - json_object_object_add(obj, key,
  19. - _lua_to_json(L, lua_gettop(L) - 1));
  20. + if (key)
  21. + json_object_object_add(obj, key,
  22. + _lua_to_json(L, lua_gettop(L) - 1));
  23. lua_pop(L, 2);
  24. }