From 5128f7d2f97c6aee83e54a3e03d2403911146df8 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 7 Dec 2014 16:32:40 -0500 Subject: [PATCH] prevent crash on invalid data --- src/socket.io/posts.js | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index b41aedc91d..d6bb4b8c53 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -70,23 +70,29 @@ SocketPosts.reply = function(socket, data, callback) { }; SocketPosts.getVoters = function(socket, data, callback) { - var pid = data.pid, - cid = data.cid, - uid = socket.uid; + if (!data || !data.pid || !data.cid) { + return callback(new Error('[[error:invalid-data]]')); + } - async.parallel([ - function(next) { - user.isAdministrator(uid, next); + var pid = data.pid, + cid = data.cid; + + async.parallel({ + isAdmin: function(next) { + user.isAdministrator(socket.uid, next); }, - function(next) { - user.isModerator(uid, cid, next); + isModerator: function(next) { + user.isModerator(socket.uid, cid, next); } - ], function(err, tests) { - if (tests[0] || tests[1]) { + }, function(err, tests) { + if (err) { + return callback(err); + } + + if (tests.isAdmin || tests.isModerator) { getVoters(pid, callback); } - }) - + }); }; function getVoters(pid, callback) {