Skip to content
Browse files

Restricts function calls to only functions that exist

Changed arguments index mismatch

Added missing this to availableFunctions
  • Loading branch information...
1 parent cb811b0 commit adbe86c7c9dfc2f80e275e63de90a39de7e63145 @sridatta sridatta committed Aug 10, 2011
Showing with 15 additions and 9 deletions.
  1. +15 −9 lib/support.js
View
24 lib/support.js
@@ -13,20 +13,21 @@ exports.initialize = function(nowjs){
Support.prototype._startHandshake = function(){
this.socket.write(JSON.stringify({type:'new'}));
- }
+ };
Support.prototype._attachListeners = function(){
var self = this;
- this.socket.on('connect', function(){self._startHandshake()});
- this.socket.on('data', function(message){self._handleMessage(message)});
- }
+ this.socket.on('connect', function(){self._startHandshake();});
+ this.socket.on('data', function(message){self._handleMessage(message);});
+ };
Support.prototype.getRemoteFunction = function(fn) {
var self = this;
+ if(this.availableFunctions[fn] == undefined){throw new Error("No such function: " + fn);};
return function(){
var args = [];
- for (var i = 1, ii = arguments.length; i < ii; i++) {
- args[i-1] = arguments[i];
+ for (var i = 0, ii = arguments.length; i < ii; i++) {
+ args[i] = arguments[i];
}
for (i = 0, ii = args.length; i < ii; i++) {
if (typeof args[i] === 'function') {
@@ -40,8 +41,8 @@ exports.initialize = function(nowjs){
}
self.socket.write(JSON.stringify({type: 'rfc',fqn:fn, args:args}));
- }
- }
+ };
+ };
Support.prototype._handleMessage = function(message){
message = JSON.parse(message.toString());
@@ -89,8 +90,13 @@ exports.initialize = function(nowjs){
theFunction = nowjs.closures[message.fqn];
theFunction.apply({}, args);
break;
+ case 'functionList':
+ var funcs = message.functions;
+ for(var i = 0, ll = funcs.length; i < ll; i++){
+ this.availableFunctions[funcs[i]] = true;
+ }
}
- }
+ };
return Support;

0 comments on commit adbe86c

Please sign in to comment.
Something went wrong with that request. Please try again.