[MacRuby] #1025: Sandbox#apply! causes segfault when no argument is passed to constructor.
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------+---------------------------------------------- Easy one to reproduce: Sandbox.new.apply! Running on -latest. -- Ticket URL: <http://www.macruby.org/trac/ticket/1025> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: -----------------------------+---------------------------------------------- Changes (by lsansonetti@…): * milestone: => MacRuby 1.0 -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:1> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: -----------------------------+---------------------------------------------- Comment(by watson1978@…): I attach a patch. please check it :) {{{ #!diff diff --git a/sandbox.c b/sandbox.c index 9cfc172..3faff18 100644 --- a/sandbox.c +++ b/sandbox.c @@ -86,6 +86,9 @@ rb_sandbox_apply(VALUE self, SEL sel) rb_sandbox_t *box; Data_Get_Struct(self, rb_sandbox_t, box); char *error = NULL; + if (box->profile == NULL || box->flags == 0) { + rb_raise(rb_eRuntimeError, "needs a profile."); + } if (sandbox_init(box->profile, box->flags, &error) == -1) { rb_raise(rb_eSecurityError, "Couldn't apply sandbox: `%s`", error); } }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:2> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: fixed Keywords: | -----------------------------+---------------------------------------------- Changes (by pthomson@…): * status: new => closed * resolution: => fixed Comment: Nice catch, watson. Fixed in r5122. -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:3> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -----------------------------+---------------------------------------------- Changes (by lsansonetti@…): * status: closed => reopened * resolution: fixed => Comment: I reverted your commit, as it's not the right way to fix this bug (as #initialize is defined with an arity of 1, an exception should be raised instead). -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:4> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -----------------------------+---------------------------------------------- Comment(by watson1978@…): Case of Segfault: {{{ $ DYLD_LIBRARY_PATH=. gdb --args ./macruby -e 'Sandbox.new.apply!' (gdb) b rb_sandbox_init Breakpoint 1 at 0x20c49ba554b042: file sandbox.c, line 34. (gdb) r Starting program: /Users/watson/src/macruby-trunk-svn/macruby -e Sandbox.new.apply\! Reading symbols for shared libraries .++++........................ done Reading symbols for shared libraries . done Reading symbols for shared libraries .. done Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000068 0x00007fff88414339 in flockfile () (gdb) }}} Case of Success: {{{ $ DYLD_LIBRARY_PATH=. gdb --args ./macruby -e 'Sandbox.no_internet.apply!' (gdb) b rb_sandbox_init Breakpoint 1 at 0x20c49ba554b042: file sandbox.c, line 34. (gdb) r Starting program: /Users/watson/src/macruby-trunk-svn/macruby -e Sandbox.no_internet.apply\! Reading symbols for shared libraries .++++........................ done Reading symbols for shared libraries . done Reading symbols for shared libraries .. done Program exited normally. (gdb) }}} Will it be a meaning that it is a problem that #initialize is not called? -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:5> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -----------------------------+---------------------------------------------- Comment(by lsansonetti@…): Watson: yes, there is a deeper bug in MacRuby. Normally, an ArgError exception should be raised, because #initialize is defined with arity 1. I think there is also a dup of this bug in another ticket (for another class). -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:6> MacRuby <http://macruby.org/>
#1025: Sandbox#apply! causes segfault when no argument is passed to constructor. -----------------------------+---------------------------------------------- Reporter: rob@… | Owner: lsansonetti@… Type: defect | Status: reopened Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Resolution: Keywords: | -----------------------------+---------------------------------------------- Comment(by watson1978@…): I see :) [[BR]] By the way, I think whether the following changes are necessary in rb_sandbox_init. {{{ #!diff diff --git a/sandbox.c b/sandbox.c index 9cfc172..145007a 100644 --- a/sandbox.c +++ b/sandbox.c @@ -33,7 +33,7 @@ rb_sandbox_init(VALUE obj, SEL sel, VALUE profile) Data_Get_Struct(obj, rb_sandbox_t, box); GC_WB(&box->profile, ruby_strdup(RSTRING_PTR(profile))); - box->flags = 0; + box->flags = SANDBOX_NAMED; return obj; } }}} Before changing it, raise a SecurityError: {{{ $ DYLD_LIBRARY_PATH=. ./macruby -e 'Sandbox.new("no-internet").apply!' -e:1:in `<main>': Couldn't apply sandbox: `line 1: unbound variable: no- internet ` (SecurityError) }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1025#comment:7> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby