cowboyd/therubyracer — Issue #144: Protecting against segfault
Author: callumj
Created: 2012-02-29 09:47:46+00:00
State: open

I'd look to use RubyRacer to allow users to write JS expressions which are evaluated server side to return a value for rendering.

I managed to segfault my IRB instance by executing code

```javascript
if (level >= 50) {
{status: "ok", color: "red"};
} else {
{status: "fail", color: "black"};
}
```

resulting a crash in the Ruby interpretor.

```
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:96: [BUG] Segmentation fault
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]

-- control frame ----------
c:0036 p:---- s:0129 b:0129 l:000128 d:000128 CFUNC :Enter
c:0035 p:0043 s:0126 b:0126 l:000125 d:000125 METHOD /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:96
c:0034 p:0165 s:0123 b:0123 l:000113 d:000122 BLOCK /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:21
c:0033 p:0028 s:0118 b:0118 l:000117 d:000117 METHOD /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/portal.rb:16
c:0032 p:0057 s:0114 b:0114 l:000113 d:000113 METHOD /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:10
c:0031 p:---- s:0110 b:0110 l:000109 d:000109 FINISH
c:0030 p:---- s:0108 b:0108 l:000107 d:000107 CFUNC :new
c:0029 p:0064 s:0105 b:0105 l:000104 d:000104 METHOD /Users/callumj/Development/CGR/callum-app/app/models/risk/risk.rb:478
c:0028 p:0011 s:0101 b:0101 l:000d88 d:000100 EVAL (irb):6
c:0027 p:---- s:0099 b:0099 l:000098 d:000098 FINISH
c:0026 p:---- s:0097 b:0097 l:000096 d:000096 CFUNC :eval
c:0025 p:0028 s:0090 b:0090 l:000089 d:000089 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/workspace.rb:80
c:0024 p:0033 s:0083 b:0082 l:000081 d:000081 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/context.rb:254
c:0023 p:0031 s:0077 b:0077 l:000db8 d:000076 BLOCK /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:159
c:0022 p:0042 s:0069 b:0069 l:000068 d:000068 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:273
c:0021 p:0011 s:0064 b:0064 l:000db8 d:000063 BLOCK /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:156
c:0020 p:0144 s:0060 b:0060 l:000043 d:000059 BLOCK /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:243
c:0019 p:---- s:0057 b:0057 l:000056 d:000056 FINISH
c:0018 p:---- s:0055 b:0055 l:000054 d:000054 CFUNC :loop
c:0017 p:0009 s:0052 b:0052 l:000043 d:000051 BLOCK /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229
c:0016 p:---- s:0050 b:0050 l:000049 d:000049 FINISH
c:0015 p:---- s:0048 b:0048 l:000047 d:000047 CFUNC :catch
c:0014 p:0023 s:0044 b:0044 l:000043 d:000043 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228
c:0013 p:0046 s:0041 b:0041 l:000db8 d:000db8 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:155
c:0012 p:0011 s:0038 b:0038 l:0020e8 d:000037 BLOCK /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:70
c:0011 p:---- s:0036 b:0036 l:000035 d:000035 FINISH
c:0010 p:---- s:0034 b:0034 l:000033 d:000033 CFUNC :catch
c:0009 p:0183 s:0030 b:0030 l:0020e8 d:0020e8 METHOD /Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:69
c:0008 p:0222 s:0025 b:0025 l:000570 d:000570 METHOD /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands/console.rb:45
c:0007 p:0019 s:0021 b:0021 l:000020 d:000020 METHOD /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands/console.rb:8
c:0006 p:0615 s:0017 b:0017 l:000016 d:000016 TOP /Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands.rb:40
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC :require
c:0003 p:0061 s:0006 b:0006 l:000348 d:0006f8 EVAL script/rails:6
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:000348 d:000348 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
script/rails:6:in `

'
script/rails:6:in `require'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands.rb:40:in `'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands/console.rb:8:in `start'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/railties-3.1.3/lib/rails/commands/console.rb:45:in `start'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `start'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `catch'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:70:in `block in start'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:159:in `block (2 levels) in eval_input'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/context.rb:254:in `evaluate'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/workspace.rb:80:in `evaluate'
/Users/callumj/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/workspace.rb:80:in `eval'
(irb):6:in `irb_binding'
/Users/callumj/Development/CGR/callum-app/app/models/risk/risk.rb:478:in `material_risk_level'
/Users/callumj/Development/CGR/callum-app/app/models/risk/risk.rb:478:in `new'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:10:in `initialize'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/portal.rb:16:in `lock'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:21:in `block in initialize'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:96:in `enter'
/Users/callumj/.rvm/gems/ruby-1.9.2-p290@callum-app/gems/therubyracer-0.9.9/lib/v8/context.rb:96:in `Enter'

-- C level backtrace information -------------------------------------------

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html
```