aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2008-10-23 02:49:43 +0500
committerWaqas Hussain <waqas20@gmail.com>2008-10-23 02:49:43 +0500
commitc3ca55e0195d03c3e0c23590c387c49068be7723 (patch)
tree85ba4b30c392489ff3a3cc4291e2881741f5a35a
parent9bcfe122c05a7082b83e8b0aa002c936e5b0ec8c (diff)
downloadprosody-c3ca55e0195d03c3e0c23590c387c49068be7723.tar.gz
prosody-c3ca55e0195d03c3e0c23590c387c49068be7723.zip
Fixed: datamanager.store and datamanager.load could crash when username or host arguments were nil. (useful for server specific and global data).
-rw-r--r--util/datamanager.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/util/datamanager.lua b/util/datamanager.lua
index 1deb6b3d..f4ae958c 100644
--- a/util/datamanager.lua
+++ b/util/datamanager.lua
@@ -68,16 +68,25 @@ end
function load(username, host, datastore)
local data, ret = loadfile(getpath(username, host, datastore));
- if not data then log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+ if not data then
+ log("warn", "Failed to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
setfenv(data, {});
local success, ret = pcall(data);
- if not success then log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..username.."@"..host); return nil; end
+ if not success then
+ log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
return ret;
end
function store(username, host, datastore, data)
local f, msg = io_open(getpath(username, host, datastore), "w+");
- if not f then log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..username.."@"..host); return nil; end
+ if not f then
+ log("error", "Unable to write to "..datastore.." storage ('"..msg.."') for user: "..(username or nil).."@"..(host or nil));
+ return nil;
+ end
f:write("return ");
simplesave(f, data);
f:close();