1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] Check capname of tigetstr/tigetflag/tigetnum

Incorrect arguments can cause SEGV.

https://github.com/ruby/reline/commit/a58748bcf9
This commit is contained in:
aycabta 2022-01-02 11:44:45 +09:00 committed by git
parent f375b6414d
commit 76181ae940
2 changed files with 6 additions and 0 deletions

View file

@ -121,6 +121,7 @@ module Reline::Terminfo
end
def self.tigetstr(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
capability = @tigetstr.(capname)
case capability.to_i
when 0, -1
@ -138,6 +139,7 @@ module Reline::Terminfo
end
def self.tigetflag(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
flag = @tigetflag.(capname).to_i
case flag
when -1
@ -149,6 +151,7 @@ module Reline::Terminfo
end
def self.tigetnum(capname)
raise TerminfoError, "capname is not String: #{capname.inspect}" unless capname.is_a?(String)
num = @tigetnum.(capname).to_i
case num
when -2

View file

@ -14,6 +14,7 @@ class Reline::Terminfo::Test < Reline::TestCase
def test_tigetstr_with_error
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetstr('unknown') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetstr(nil) }
end
def test_tiparm
@ -43,6 +44,7 @@ class Reline::Terminfo::Test < Reline::TestCase
def test_tigetflag_with_error
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag('cuu') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag('unknown') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetflag(nil) }
end
def test_tigetnum
@ -54,5 +56,6 @@ class Reline::Terminfo::Test < Reline::TestCase
def test_tigetnum_with_error
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum('cuu') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum('unknown') }
assert_raise(Reline::Terminfo::TerminfoError) { Reline::Terminfo.tigetnum(nil) }
end
end if Reline::Terminfo.enabled?