Skip to content

Node.js based forum software built for the modern web

prevent crash on invalid data

barisusakli5128f7d2f97c
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) {
+ if (!data || !data.pid || !data.cid) {
+ return callback(new Error('[[error:invalid-data]]'));
+ }
+
var pid = data.pid,
- cid = data.cid,
- uid = socket.uid;
+ cid = data.cid;
- async.parallel([
- function(next) {
- user.isAdministrator(uid, next);
+ 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]) {
- getVoters(pid, callback);
+ }, function(err, tests) {
+ if (err) {
+ return callback(err);
}
- })
+ if (tests.isAdmin || tests.isModerator) {
+ getVoters(pid, callback);
+ }
+ });
};
function getVoters(pid, callback) {