mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
sprintf.c: width too big
* sprintf.c (rb_str_format): explicitly reject too big negative width, instead of an empty string. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
151c170472
commit
53737990fe
2 changed files with 7 additions and 0 deletions
|
@ -648,6 +648,7 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||
if (width < 0) {
|
||||
flags |= FMINUS;
|
||||
width = -width;
|
||||
if (width < 0) rb_raise(rb_eArgError, "width too big");
|
||||
}
|
||||
p++;
|
||||
goto retry;
|
||||
|
|
|
@ -514,6 +514,12 @@ class TestSprintf < Test::Unit::TestCase
|
|||
assert_equal("!", sprintf("%*c", 0, ?!.ord), bug)
|
||||
end
|
||||
|
||||
def test_negative_width_overflow
|
||||
assert_raise_with_message(ArgumentError, /too big/) do
|
||||
sprintf("%*s", RbConfig::LIMITS["INT_MIN"], "")
|
||||
end
|
||||
end
|
||||
|
||||
def test_no_hidden_garbage
|
||||
fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
|
||||
ObjectSpace.count_objects(res = {}) # creates strings on first call
|
||||
|
|
Loading…
Reference in a new issue