From: Waqas Hussain Date: Thu, 2 Jun 2011 00:36:15 +0000 (+0500) Subject: util.json: Fixed handling of truncated JSON. X-Git-Url: https://git.enpas.org/?a=commitdiff_plain;h=11090febb1c7a8a887f6ad14f122d43b0654024f;p=prosody.git util.json: Fixed handling of truncated JSON. --- diff --git a/util/json.lua b/util/json.lua index 05453703..cfa84a4b 100644 --- a/util/json.lua +++ b/util/json.lua @@ -134,12 +134,14 @@ end function json.decode(json) + json = json.." "; -- appending a space ensures valid json wouldn't touch EOF local pos = 1; local current = {}; local stack = {}; local ch, peek; local function next() ch = json:sub(pos, pos); + if ch == "" then error("Unexpected EOF"); end pos = pos+1; peek = json:sub(pos, pos); return ch;