[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 коммит произвёл git
Родитель f375b6414d
Коммит 76181ae940
2 изменённых файлов: 6 добавлений и 0 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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?