From e1ba26dafecb85a73a0856ff001594acb25c4db4 Mon Sep 17 00:00:00 2001 From: Waqas Hussain Date: Thu, 2 Jun 2011 05:36:15 +0500 Subject: util.json: Fixed handling of truncated JSON. --- util/json.lua | 2 ++ 1 file changed, 2 insertions(+) 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; -- cgit v1.2.3 From 7037ff8b95c6d1860b1ca9e42a9916ac237419cc Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 2 Jun 2011 02:30:26 +0100 Subject: mod_storage_sql: Switch to MEDIUMTEXT for the 'value' column when using MySQL, as it imposes a 64K limit otherwise, potentially truncating data. Automatically upgrades existing tables. --- plugins/mod_storage_sql.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index b88efb64..dd148704 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -68,6 +68,8 @@ local function create_table() local create_sql = "CREATE TABLE `prosody` (`host` TEXT, `user` TEXT, `store` TEXT, `key` TEXT, `type` TEXT, `value` TEXT);"; if params.driver == "PostgreSQL" then create_sql = create_sql:gsub("`", "\""); + elseif params.driver == "MySQL" then + create_sql = create_sql:gsub("`value` TEXT", "`value` MEDIUMTEXT"); end local stmt = connection:prepare(create_sql); @@ -91,6 +93,22 @@ local function create_table() if not(ok and commit_ok) then module:log("warn", "Failed to create index (%s), lookups may not be optimised", err or commit_err); end + else -- COMPAT: Upgrade tables from 0.8.0 + -- Failed to create, but check existing MySQL table here + local stmt = connection:prepare("SHOW COLUMNS FROM prosody WHERE Field='value' and Type='text'"); + local ok = stmt:execute(); + local commit_ok = connection:commit(); + if ok and commit_ok then + if stmt:rowcount() > 0 then + local stmt = connection:prepare("ALTER TABLE prosody MODIFY COLUMN `value` MEDIUMTEXT"); + local ok = stmt:execute(); + local commit_ok = connection:commit(); + if ok and commit_ok then + module:log("info", "Database table automatically upgraded"); + end + end + repeat until not stmt:fetch(); + end end end end -- cgit v1.2.3