Skip to content
Browse files

Harden the eval!

  • Loading branch information...
1 parent 54363b6 commit fe9059a445e39e8b8dca354b0b492b58ef3ba9d5 Chris Joel committed Mar 2, 2012
Showing with 39 additions and 6 deletions.
  1. +19 −0 src/eval-helper.js
  2. +20 −6 src/scripts/parse.coffee
View
19 src/eval-helper.js
@@ -0,0 +1,19 @@
+var vm = require('vm');
+
+process.on(
+ 'message',
+ function(msg) {
+
+ var evalable = msg.evalable,
+ result;
+
+ try {
+ result = vm.runInNewContext(evalable);
+ } catch(e) {
+ result = e.message;
+ }
+
+ process.send({result: result});
+ process.exit(0);
+ }
+);
View
26 src/scripts/parse.coffee
@@ -1,5 +1,6 @@
jsdom = require "jsdom"
-vm = require "vm"
+path = require "path"
+child = require "child_process"
module.exports = (robot) ->
@@ -27,9 +28,22 @@ module.exports = (robot) ->
evalable = msg.match[1]
- try
- response = vm.runInNewContext evalable
- catch e
- response = e.message
+ originalExecPath = process.execPath
+
+ # EPIC HACK WHAT! (fuck CoffeeScript)
+ process.execPath = "/home/chris/local/bin/node"
+
+ runner = child.fork path.join __dirname, "../eval-helper.js"
+
+ process.execPath = originalExecPath
+ runner.on 'message', (response) ->
+ msg.send response.result
+ clearTimeout runTimer
+
+ runner.send { evalable: evalable }
+
+ runTimer = setTimeout (->
+ runner.kill 'SIGKILL'
+ msg.send "Ptooey. That's all I have to say about your pitiful long-running script. Try again :P"
+ ), 3000
- msg.send response

0 comments on commit fe9059a

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