diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-03-14 09:07:06 +0900 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-03-14 09:07:06 +0900 |
| commit | 4b1e5d47b326d0ca3272370b8d13b85344f929fd (patch) | |
| tree | 2463f49757b68094abf5b0655d17efeb434ec258 | |
| parent | 191ee2596cc7b22e3213d82bab1a48ae6152b475 (diff) | |
| parent | d8c4fe7bcb07b4268184b526652311f28f0ce3a5 (diff) | |
| download | mruby-4b1e5d47b326d0ca3272370b8d13b85344f929fd.tar.gz mruby-4b1e5d47b326d0ca3272370b8d13b85344f929fd.zip | |
Merge pull request #3503 from nobu/bug/sprintf-oob
Fix out-of-bound access
| -rw-r--r-- | mrbgems/mruby-sprintf/src/sprintf.c | 1 | ||||
| -rw-r--r-- | mrbgems/mruby-sprintf/test/sprintf.rb | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/mrbgems/mruby-sprintf/src/sprintf.c b/mrbgems/mruby-sprintf/src/sprintf.c index cc00198d0..09a26f827 100644 --- a/mrbgems/mruby-sprintf/src/sprintf.c +++ b/mrbgems/mruby-sprintf/src/sprintf.c @@ -567,6 +567,7 @@ mrb_str_format(mrb_state *mrb, int argc, const mrb_value *argv, mrb_value fmt) mrb_sym id = 0; for (t = p; t < end && *t != '%'; t++) ; + if (t + 1 == end) ++t; PUSH(p, t - p); if (t >= end) goto sprint_exit; /* end of fmt string */ diff --git a/mrbgems/mruby-sprintf/test/sprintf.rb b/mrbgems/mruby-sprintf/test/sprintf.rb index ccbd95d51..178904d60 100644 --- a/mrbgems/mruby-sprintf/test/sprintf.rb +++ b/mrbgems/mruby-sprintf/test/sprintf.rb @@ -30,3 +30,14 @@ assert("String#% with invalid chr") do end end end + +assert("String#% invalid format") do + assert_raise ArgumentError do + "%?" % "" + end +end + +assert("String#% invalid format shared substring") do + fmt = ("x"*30+"%!")[0...-1] + assert_equal fmt, sprintf(fmt, "") +end |
