From 0854193a684acc2b3a13ab28091a4397000c8822 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 17 Dec 2016 18:04:30 +0000 Subject: sprintf.c: fix width underflow * sprintf.c (rb_str_format): fix memory corruption by width underflow. https://github.com/mruby/mruby/issues/3347 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57108 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- sprintf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sprintf.c') diff --git a/sprintf.c b/sprintf.c index 5884926b3e..4342904bdc 100644 --- a/sprintf.c +++ b/sprintf.c @@ -705,10 +705,10 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt) CHECK(n); rb_enc_mbcput(c, &buf[blen], enc); blen += n; - FILL(' ', width-1); + if (width > 1) FILL(' ', width-1); } else { - FILL(' ', width-1); + if (width > 1) FILL(' ', width-1); CHECK(n); rb_enc_mbcput(c, &buf[blen], enc); blen += n; -- cgit v1.2.1