Skip to content

Commit

Permalink
catch invalid rpc params (close #31)
Browse files Browse the repository at this point in the history
  • Loading branch information
hobbyquaker committed Nov 16, 2018
1 parent 1966351 commit 86395e9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions nodes/ccu-connection.js
Expand Up @@ -11,6 +11,11 @@ const binrpc = require('binrpc');

const pkg = require(path.join(__dirname, '..', 'package.json'));

// https://stackoverflow.com/a/37837872
function isIterable(obj) {
return obj != null && typeof obj[Symbol.iterator] === 'function';
}

module.exports = function (RED) {
RED.log.info('node-red-contrib-ccu version: ' + pkg.version);

Expand Down Expand Up @@ -1073,7 +1078,11 @@ module.exports = function (RED) {
if (method === 'event') {
method = 'eventSingle';
}
this.rpcMethods[method](err, params, callback);
if (isIterable(params)) {
this.rpcMethods[method](err, params, callback);
} else {
this.logger.error('rpc <', protocol, 'method', method, 'params not iterable', JSON.stringify(params));
}
});
});
this.servers[protocol].on('NotFound', (method, params) => {
Expand Down Expand Up @@ -1378,7 +1387,11 @@ module.exports = function (RED) {
result.push('');
} else if (this.rpcMethods[call.methodName]) {
pong = false;
this.rpcMethods[call.methodName](call.params || [], res => result.push(res));
if (isIterable(call.params)) {
this.rpcMethods[call.methodName](call.params || [], res => result.push(res));
} else {
this.logger.error('rpc <', protocol, 'method', call.methodName, 'params not iterable', JSON.stringify(call.params));
}
}
});
queue.forEach(call => {
Expand Down

0 comments on commit 86395e9

Please sign in to comment.