Skip to content

Commit

Permalink
Protect against segfault upon unexpected parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewd committed Sep 19, 2009
1 parent 6e7d8b1 commit f6acf53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/spidermonkey/runtime.c
Expand Up @@ -127,6 +127,10 @@ static VALUE native_compile(VALUE self, VALUE script, VALUE filename, VALUE line
static VALUE evaluate_compiled_script(VALUE self, VALUE compiled_script)
{
JohnsonRuntime* runtime;

if (!ruby_value_is_script_proxy(compiled_script))
rb_raise(rb_eArgError, "Compiled JS Script expected");

Data_Get_Struct(self, JohnsonRuntime, runtime);

JSContext * context = johnson_get_current_context(runtime);
Expand Down
12 changes: 12 additions & 0 deletions test/johnson/runtime_test.rb
Expand Up @@ -60,5 +60,17 @@ def test_try_to_gc
GC.start
}
end

def test_evaluated_compiled_script_checks_argument_type
assert_raises(ArgumentError) {
@runtime.evaluate_compiled_script(nil)
}
assert_raises(ArgumentError) {
@runtime.evaluate_compiled_script(17)
}
assert_raises(ArgumentError) {
@runtime.evaluate_compiled_script("3+9")
}
end
end
end

0 comments on commit f6acf53

Please sign in to comment.