[MacRuby] #842: Can't catch the exception of SecurityError Level 4.
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Test Script: {{{ #!ruby $ cat test_safe.rb class C def m $SAFE end end def run(&block) begin block.call rescue SecurityError => e p "ok : #{e}" else p "ng" end end puts "** level 1" b = lambda { $SAFE = 1 eval "1 + 1".taint } run{ b.call } puts "** level 2" b = lambda { $SAFE = 2 Dir.chdir("..") } run{ b.call } puts "** level 3" b = lambda { $SAFE = 3 "1 + 1".untaint } run{ b.call } puts "** level 4" d = lambda { $SAFE = 4 dclass = Class.new(C) dclass.send(:alias_method, :mm, :m) dclass.new }.call run{ d.mm } b = lambda { d = Dir.open('.') $SAFE = 4 d.close } run{ b.call } }}} Result of Ruby 1.9.1: {{{ $ ruby test_safe.rb ** level 1 "ok : Insecure operation - eval" ** level 2 "ok : Insecure operation `chdir' at level 2" ** level 3 "ok : Insecure operation `untaint' at level 3" ** level 4 "ok : calling insecure method: mm" "ok : Insecure: operation on trusted Dir" }}} Result of MacRuby Trunk: {{{ $ macruby test_safe.rb ** level 1 "ok : Insecure operation: -r" ** level 2 "ok : Insecure operation at level 2" ** level 3 "ok : Insecure operation at level 3" ** level 4 /Users/watson/test/ruby/macruby/test_safe.rb:9:in `run': Insecure operation at level 4 (SecurityError) from /Users/watson/test/ruby/macruby/test_safe.rb:1:in `<main>' }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/842> MacRuby <http://macruby.org/>
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by martinlagardette@…): The problem is not that the exception cannot be catched. It has been catched, but it raises again with the `#p` operation. The real problem is that the $SAFE value is not set only for the block it's defined in: {{{ #!ruby # test_safe.rb p $SAFE -> { $SAFE = 3 }.call p $SAFE }}} {{{ $> ruby19 test_safe.rb 0 0 $> macruby test_safe.rb 0 3 $> }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:1> MacRuby <http://macruby.org/>
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by martinlagardette@…): It's especially evil because `$SAFE` looks like a global var but doesn't behave like one: {{{ #!ruby $SAFE = 1 p $SAFE lambda { $SAFE = 3 }.call p $SAFE puts "-----" $RANDOM = 1 p $RANDOM lambda { $RANDOM = 3 }.call p $RANDOM }}} {{{ $> ruby19 test_safe.rb 1 1 ----- 1 3 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:2> MacRuby <http://macruby.org/>
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Interesting indeed. {{{ $ ruby1.9 -e 'def foo; yield; end; foo { $SAFE=3 }; p $SAFE' 3 $ ruby1.9 -e 'def foo(&b); b.call; end; foo { $SAFE=3 }; p $SAFE' 0 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:3> MacRuby <http://macruby.org/>
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): Safe level seems to treat an exceptional in Proc Context. I found it in CRuby's Changelog. {{{ Fri Apr 11 10:27:29 1997 Yukihiro Matsumoto <matz@caelum.co.jp> * version 1.0-970411 * Makefile.in: create libruby.a before linking ruby. * string.c (str_strip_bang): >0x80 characters for isspace(). * eval.c (proc_call): set safe-level temporally * eval.c (proc_s_new): save safe-level in the proc context. }}} http://ftp.ruby-lang.org/pub/ruby/1.1a/ChangeLog-1.1 Cannot drop a Safe-Level when put up it once, I think that Proc was made to such behavior. -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:4> MacRuby <http://macruby.org/>
#842: Can't catch the exception of SecurityError Level 4. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Maybe this was designed for Thread.new {}. In any case, it's intended behavior so we need to fix it, somehow. I guess this cannot be solved at compilation time since eval & friends can also change $SAFE. -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:5> MacRuby <http://macruby.org/>
#842: setting $SAFE inside Proc should not override top-level $SAFE ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): Renamed ticket accordingly. -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:6> MacRuby <http://macruby.org/>
#842: setting $SAFE inside Proc should not override top-level $SAFE ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * milestone: => MacRuby 1.0 Comment: Screening for 1.0 (tentative). -- Ticket URL: <http://www.macruby.org/trac/ticket/842#comment:7> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby