ext/tk: remove $SAFE 2..4 code

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-09-24 01:37:14 +00:00
parent 61847a8279
commit c97a6987b6
11 changed files with 18 additions and 83 deletions

View File

@ -171,7 +171,7 @@ module TclTklib
: a target event. : a target event.
: If set DONT_WAIT flag and no event for processing, returns : If set DONT_WAIT flag and no event for processing, returns
: false immediately. : false immediately.
: If $SAFE >= 4, or $SAFE >= 1 and the flag is tainted, : If $SAFE >= 1 and the flag is tainted,
: force to set DONT_WAIT flag. : force to set DONT_WAIT flag.
set_eventloop_tick(timer_tick) set_eventloop_tick(timer_tick)
@ -183,7 +183,6 @@ module TclTklib
: However, if the eventloop thread is the only thread, : However, if the eventloop thread is the only thread,
: timer_tick cannot be set to 0. If 0, then is set to 100 ms : timer_tick cannot be set to 0. If 0, then is set to 100 ms
: automatically (see NO_THREAD_INTERRUPT_TIME on tcltklib.c). : automatically (see NO_THREAD_INTERRUPT_TIME on tcltklib.c).
: On $SAFE >= 4, cannot call this method.
get_eventloop_tick get_eventloop_tick
: Get current value of 'timer_tick' : Get current value of 'timer_tick'
@ -194,7 +193,6 @@ module TclTklib
: Default value is 20 (ms). : Default value is 20 (ms).
: If the eventloop thread is the only thread, this value is : If the eventloop thread is the only thread, this value is
: invalid. : invalid.
: On $SAFE >= 4, cannot call this method.
get_no_event_wait get_no_event_wait
: Get current value of 'no_event_wait'. : Get current value of 'no_event_wait'.
@ -207,7 +205,6 @@ module TclTklib
: when no event for processing (And then, the eventloop thread : when no event for processing (And then, the eventloop thread
: sleeps 'no_event_wait' mili-seconds). : sleeps 'no_event_wait' mili-seconds).
: 'loop_max == 800' and 'no_event_tick == 10' are default. : 'loop_max == 800' and 'no_event_tick == 10' are default.
: On $SAFE >= 4, cannot call this method.
get_eventloop_weight get_eventloop_weight
: Get current values of 'loop_max' and 'no_event_tick'. : Get current values of 'loop_max' and 'no_event_tick'.
@ -223,7 +220,6 @@ module TclTklib
: interpreter kills the eventloop thread. Even if such : interpreter kills the eventloop thread. Even if such
: situation, when abort_on_exception == false or nil, : situation, when abort_on_exception == false or nil,
: the eventloop ignores the exception and continue to working. : the eventloop ignores the exception and continue to working.
: On $SAFE >= 4, cannot call this method.
mainloop_abort_on_exception mainloop_abort_on_exception
: Get current status of that. : Get current status of that.
@ -294,7 +290,6 @@ class TclTkIp
: interpreter. Default is false. However, if the parent : interpreter. Default is false. However, if the parent
: interpreter is a safe interpreter, the created interpreter is : interpreter is a safe interpreter, the created interpreter is
: a safe interpreter (ignore 'safe' argument value). : a safe interpreter (ignore 'safe' argument value).
: If $SAFE >= 4, can create a safe interpreter only.
make_safe make_safe
: Make the interpreter to the safe interpreter, and returns : Make the interpreter to the safe interpreter, and returns
@ -314,7 +309,7 @@ class TclTkIp
allow_ruby_exit=(mode) allow_ruby_exit=(mode)
: Change the mode of 'allow_ruby_exit?'. : Change the mode of 'allow_ruby_exit?'.
: If $SAFE >= 4 or the interpreter is a "safe" interpreter, : If the interpreter is a "safe" interpreter,
: this is not permitted (raise an exception). : this is not permitted (raise an exception).
delete delete
@ -335,7 +330,6 @@ class TclTkIp
: Restart Tk part of the interpreter. : Restart Tk part of the interpreter.
: Use this when you need Tk functions after destroying the : Use this when you need Tk functions after destroying the
: root widget. : root widget.
: On $SAFE >= 4, cannot call this method.
_eval(str) _eval(str)
_invoke(*args) _invoke(*args)

View File

@ -272,7 +272,7 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 象となっている種類のイベントが発生するまで待ち続ける. : 象となっている種類のイベントが発生するまで待ち続ける.
: DONT_WAIT を指定していた場合,処理対象イベントがなくても : DONT_WAIT を指定していた場合,処理対象イベントがなくても
: すぐに終了し false を返す. : すぐに終了し false を返す.
: $SAFE >= 4 か,$SAFE >= 1 かつ flag が汚染されているならば : $SAFE >= 1 かつ flag が汚染されているならば
: flag には DONT_WAIT が強制的に付けられる. : flag には DONT_WAIT が強制的に付けられる.
set_eventloop_tick(timer_tick) set_eventloop_tick(timer_tick)
@ -288,7 +288,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 定される. : 定される.
: 詳細な説明は略すが,これは CPU パワーを節約しつつ安全で : 詳細な説明は略すが,これは CPU パワーを節約しつつ安全で
: 安定した動作を実現するために実装した仕様である. : 安定した動作を実現するために実装した仕様である.
: $SAFE >= 4 では実行が禁止される.
get_eventloop_tick get_eventloop_tick
: timer_tick の現在値を返す. : timer_tick の現在値を返す.
@ -298,7 +297,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: く存在しなかった際に sleep 状態に入る時間長を指定する. : く存在しなかった際に sleep 状態に入る時間長を指定する.
: 稼働スレッドがイベントループだけの場合には意味をなさない. : 稼働スレッドがイベントループだけの場合には意味をなさない.
: デフォルトの値は 20 (ms) : デフォルトの値は 20 (ms)
: $SAFE >= 4 では実行が禁止される.
get_no_event_wait get_no_event_wait
: no_event_wait の現在値を返す. : no_event_wait の現在値を返す.
@ -316,7 +314,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: が全く発生しないままに 80 回の処理待ちイベント検査が完了 : が全く発生しないままに 80 回の処理待ちイベント検査が完了
: するとかでカウントが 800 以上になるとスレッドスイッチング : するとかでカウントが 800 以上になるとスレッドスイッチング
: が発生することになる. : が発生することになる.
: $SAFE >= 4 では実行が禁止される.
get_eventloop_weight get_eventloop_weight
: 現在の loop_max と no_event_tick との値を返す. : 現在の loop_max と no_event_tick との値を返す.
@ -336,7 +333,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: 他のインタープリタの処理継続が不可能になることがある.その : 他のインタープリタの処理継続が不可能になることがある.その
: ような場合でもエラーを無視してイベントループが稼働を続ける : ような場合でもエラーを無視してイベントループが稼働を続ける
: ことで,他のインタープリタが正常に動作し続けることができる. : ことで,他のインタープリタが正常に動作し続けることができる.
: $SAFE >= 4 では実行が禁止される.
mainloop_abort_on_exception mainloop_abort_on_exception
: Tk インタープリタ上で例外を発生した際に,イベントループをエ : Tk インタープリタ上で例外を発生した際に,イベントループをエ
@ -404,7 +400,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: たとえ明確に false を指定していたとしても,親となるインター : たとえ明確に false を指定していたとしても,親となるインター
: プリタが safe インタープリタであれば,その設定を引き継いで : プリタが safe インタープリタであれば,その設定を引き継いで
: safe インタープリタとして生成される. : safe インタープリタとして生成される.
: $SAFE >= 4 ではsafe インタープリタ以外の生成が禁止される.
make_safe make_safe
: Tcl/Tk インタープリタを safe インタープリタに変更する. : Tcl/Tk インタープリタを safe インタープリタに変更する.
@ -425,8 +420,8 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
allow_ruby_exit=(mode) allow_ruby_exit=(mode)
: 対象となるインタープリタの allow_ruby_exit? の状態を変更する. : 対象となるインタープリタの allow_ruby_exit? の状態を変更する.
: $SAFE >= 4 またはインタープリタが safe インタープリタの場合は : インタープリタが safe インタープリタの場合は変更が許されない
: 変更が許されない (例外を発生) : (例外を発生)
delete delete
: Tcl/Tk インタープリタを delete する. : Tcl/Tk インタープリタを delete する.
@ -447,7 +442,6 @@ require "tcltklib" すると, 以下のモジュール, クラスが利用可能
: Tcl/Tk インタープリタの Tk 部分の初期化,再起動を行う. : Tcl/Tk インタープリタの Tk 部分の初期化,再起動を行う.
: 一旦 root widget を破壊した後に再度 Tk の機能が必要と : 一旦 root widget を破壊した後に再度 Tk の機能が必要と
: なった場合に用いる. : なった場合に用いる.
: $SAFE >= 4 では実行が禁止される.
_eval(str) _eval(str)
_invoke(*args) _invoke(*args)

View File

@ -1265,14 +1265,6 @@ class MultiTkIp
###################################### ######################################
def initialize(master, safeip=true, keys={}) def initialize(master, safeip=true, keys={})
if $SAFE >= 4
fail SecurityError, "cannot create a new interpreter at level #{$SAFE}"
end
if safeip == nil && $SAFE >= 2
fail SecurityError, "cannot create a master-ip at level #{$SAFE}"
end
if master.deleted? && safeip == nil if master.deleted? && safeip == nil
fail RuntimeError, "cannot create a slave of a deleted interpreter" fail RuntimeError, "cannot create a slave of a deleted interpreter"
end end
@ -1307,7 +1299,7 @@ class MultiTkIp
name, safe, safe_opts, tk_opts = _parse_slaveopts(keys) name, safe, safe_opts, tk_opts = _parse_slaveopts(keys)
safe = 4 if safe && !safe.kind_of?(Fixnum) safe = 1 if safe && !safe.kind_of?(Fixnum)
@safe_base = false @safe_base = false
@ -1423,7 +1415,7 @@ class MultiTkIp
safe = master.safe_level if safe < master.safe_level safe = master.safe_level if safe < master.safe_level
@safe_level = [safe] @safe_level = [safe]
else else
@safe_level = [4] @safe_level = [1]
end end
else else
@interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts) @interp, @ip_name = master.__create_trusted_slave_obj(name, tk_opts)
@ -1615,7 +1607,7 @@ class << MultiTkIp
end end
alias new_trusted_slave new_slave alias new_trusted_slave new_slave
def new_safe_slave(safe=4, keys={}, &blk) def new_safe_slave(safe=1, keys={}, &blk)
if safe.kind_of?(Hash) if safe.kind_of?(Hash)
keys = safe keys = safe
elsif safe.kind_of?(Integer) elsif safe.kind_of?(Integer)
@ -2754,13 +2746,9 @@ class MultiTkIp
if @wait_on_mainloop[0] if @wait_on_mainloop[0]
begin begin
@wait_on_mainloop[1] += 1 @wait_on_mainloop[1] += 1
if $SAFE >= 4
_receiver_mainloop(check_root).join
else
@cmd_queue.enq([@system, 'call_mainloop', @cmd_queue.enq([@system, 'call_mainloop',
Thread.current, check_root]) Thread.current, check_root])
Thread.stop Thread.stop
end
rescue MultiTkIp_OK => ret rescue MultiTkIp_OK => ret
# return value # return value
if ret.value.kind_of?(Thread) if ret.value.kind_of?(Thread)

View File

@ -61,10 +61,6 @@ end
class RemoteTkIp class RemoteTkIp
def initialize(remote_ip, displayof=nil, timeout=5) def initialize(remote_ip, displayof=nil, timeout=5)
if $SAFE >= 4
fail SecurityError, "cannot access another interpreter at level #{$SAFE}"
end
@interp = MultiTkIp.__getip @interp = MultiTkIp.__getip
if @interp.safe? if @interp.safe?
fail SecurityError, "safe-IP cannot create RemoteTkIp" fail SecurityError, "safe-IP cannot create RemoteTkIp"
@ -199,9 +195,7 @@ class RemoteTkIp
raise SecurityError, "no permission to manipulate" unless self.manipulable? raise SecurityError, "no permission to manipulate" unless self.manipulable?
p ['_appsend', [@remote, @displayof], enc_mode, async, cmds] if $DEBUG p ['_appsend', [@remote, @displayof], enc_mode, async, cmds] if $DEBUG
if $SAFE >= 4 if $SAFE >= 1 && cmds.find{|obj| obj.tainted?}
fail SecurityError, "cannot send commands at level 4"
elsif $SAFE >= 1 && cmds.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted commands at level #{$SAFE}" fail SecurityError, "cannot send tainted commands at level #{$SAFE}"
end end

View File

@ -1785,9 +1785,7 @@ EOS
end end
def appsend(interp, async, *args) def appsend(interp, async, *args)
if $SAFE >= 4 if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send Tk commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}" fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
end end
if async != true && async != false && async != nil if async != true && async != false && async != nil
@ -1802,9 +1800,7 @@ EOS
end end
def rb_appsend(interp, async, *args) def rb_appsend(interp, async, *args)
if $SAFE >= 4 if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send Ruby commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}" fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
end end
if async != true && async != false && async != nil if async != true && async != false && async != nil
@ -1820,9 +1816,7 @@ EOS
end end
def appsend_displayof(interp, win, async, *args) def appsend_displayof(interp, win, async, *args)
if $SAFE >= 4 if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send Tk commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}" fail SecurityError, "cannot send tainted Tk commands at level #{$SAFE}"
end end
win = '.' if win == nil win = '.' if win == nil
@ -1838,9 +1832,7 @@ EOS
end end
def rb_appsend_displayof(interp, win, async, *args) def rb_appsend_displayof(interp, win, async, *args)
if $SAFE >= 4 if $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send Ruby commands at level 4"
elsif $SAFE >= 1 && args.find{|obj| obj.tainted?}
fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}" fail SecurityError, "cannot send tainted Ruby commands at level #{$SAFE}"
end end
win = '.' if win == nil win = '.' if win == nil
@ -1899,7 +1891,7 @@ EOS
INTERP_ROOT_CHECK.wait(INTERP_MUTEX) INTERP_ROOT_CHECK.wait(INTERP_MUTEX)
status = INTERP_THREAD_STATUS.value status = INTERP_THREAD_STATUS.value
if status && TkCore::INTERP.default_master? if status && TkCore::INTERP.default_master?
INTERP_THREAD_STATUS.value = nil if $SAFE < 4 INTERP_THREAD_STATUS.value = nil
raise status if status.kind_of?(Exception) raise status if status.kind_of?(Exception)
end end
} }
@ -2209,9 +2201,6 @@ module Tk
# tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath')) # tk_split_simplelist(INTERP._invoke('set', 'tcl_libPath'))
when :PLATFORM, :TCL_PLATFORM when :PLATFORM, :TCL_PLATFORM
if $SAFE >= 4
fail SecurityError, "can't get #{sym} when $SAFE >= 4"
end
INTERP._invoke_without_enc('global', 'tcl_platform') INTERP._invoke_without_enc('global', 'tcl_platform')
Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get', Hash[*tk_split_simplelist(INTERP._invoke_without_enc('array', 'get',
'tcl_platform'))] 'tcl_platform'))]
@ -3746,7 +3735,6 @@ module TkConfigMethod
@mode || false @mode || false
end end
def TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) def TkConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
fail SecurityError, "can't change the mode" if $SAFE>=4
@mode = (mode)? true: false @mode = (mode)? true: false
end end
@ -5650,9 +5638,6 @@ class TkWindow<TkObject
end end
def wait_visibility(on_thread = true) def wait_visibility(on_thread = true)
if $SAFE >= 4
fail SecurityError, "can't wait visibility at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1) on_thread &= (Thread.list.size != 1)
if on_thread if on_thread
INTERP._thread_tkwait('visibility', path) INTERP._thread_tkwait('visibility', path)
@ -5676,9 +5661,6 @@ class TkWindow<TkObject
alias thread_tkwait_visibility thread_wait_visibility alias thread_tkwait_visibility thread_wait_visibility
def wait_destroy(on_thread = true) def wait_destroy(on_thread = true)
if $SAFE >= 4
fail SecurityError, "can't wait destroy at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1) on_thread &= (Thread.list.size != 1)
if on_thread if on_thread
INTERP._thread_tkwait('window', epath) INTERP._thread_tkwait('window', epath)

View File

@ -124,7 +124,6 @@ module TkItemConfigMethod
@mode || false @mode || false
end end
def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) def TkItemConfigMethod.__set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode)
fail SecurityError, "can't change the mode" if $SAFE>=4
@mode = (mode)? true: false @mode = (mode)? true: false
end end

View File

@ -22,15 +22,9 @@ module TkOptionDB
end end
def add(pat, value, pri=None) def add(pat, value, pri=None)
# if $SAFE >= 4
# fail SecurityError, "can't call 'TkOptionDB.add' at $SAFE >= 4"
# end
tk_call('option', 'add', pat, value, pri) tk_call('option', 'add', pat, value, pri)
end end
def clear def clear
# if $SAFE >= 4
# fail SecurityError, "can't call 'TkOptionDB.crear' at $SAFE >= 4"
# end
tk_call_without_enc('option', 'clear') tk_call_without_enc('option', 'clear')
end end
def get(win, name, klass) def get(win, name, klass)

View File

@ -498,10 +498,6 @@ class TkTimer
end end
def wait(on_thread = true, check_root = false) def wait(on_thread = true, check_root = false)
if $SAFE >= 4
fail SecurityError, "can't wait timer at $SAFE >= 4"
end
unless @running unless @running
if @return_value.kind_of?(Exception) if @return_value.kind_of?(Exception)
fail @return_value fail @return_value

View File

@ -360,9 +360,6 @@ class TkVariable
end end
def wait(on_thread = false, check_root = false) def wait(on_thread = false, check_root = false)
if $SAFE >= 4
fail SecurityError, "can't wait variable at $SAFE >= 4"
end
on_thread &= (Thread.list.size != 1) on_thread &= (Thread.list.size != 1)
if on_thread if on_thread
if check_root if check_root

3
ext/tk/sample/safe-tk.rb Normal file → Executable file
View File

@ -117,9 +117,6 @@ p ip.eval_str("
:padx=>10, :pady=>7) :padx=>10, :pady=>7)
", bind) ", bind)
puts "\n---- change the safe slave IP's safe-level ==> 4 ----------"
ip.safe_level = 4
puts "\n---- call 3rd and 4th eval_proc ----------" puts "\n---- call 3rd and 4th eval_proc ----------"
p ip.eval_proc{ p ip.eval_proc{
TkLabel.new(:text=>"3rd and 4th eval_proc : $SAFE == #{$SAFE}").pack TkLabel.new(:text=>"3rd and 4th eval_proc : $SAFE == #{$SAFE}").pack

2
ext/tk/sample/tkoptdb-safeTk.rb Normal file → Executable file
View File

@ -31,7 +31,7 @@ file = File.expand_path('tkoptdb.rb', File.dirname(__FILE__))
ip = MultiTkIp.new_safeTk{ ip = MultiTkIp.new_safeTk{
# When a block is given to 'new_safeTk' method, # When a block is given to 'new_safeTk' method,
# the block is evaluated on $SAFE==4. # the block is evaluated on $SAFE==1.
ent.each{|pat, val| Tk.tk_call('option', 'add', pat, val)} ent.each{|pat, val| Tk.tk_call('option', 'add', pat, val)}
} }