summaryrefslogtreecommitdiffhomepage
path: root/src/string.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-06-27 16:32:24 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-06-27 16:32:24 +0900
commit695f29cd604787f43be1af16e38d13610bf8312b (patch)
treec3e84bc236525d69febad64fa2565a2c1f81000e /src/string.c
parent7e798405874ee3a4e3019436d8560641a5048dd3 (diff)
downloadmruby-695f29cd604787f43be1af16e38d13610bf8312b.tar.gz
mruby-695f29cd604787f43be1af16e38d13610bf8312b.zip
Add negative check in `mrb_str_resize`; fix #4062
Diffstat (limited to 'src/string.c')
-rw-r--r--src/string.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
index 5cca6d460..fd09e05dc 100644
--- a/src/string.c
+++ b/src/string.c
@@ -708,6 +708,9 @@ mrb_str_resize(mrb_state *mrb, mrb_value str, mrb_int len)
mrb_int slen;
struct RString *s = mrb_str_ptr(str);
+ if (len < 0) {
+ mrb_raisef(mrb, E_ARGUMENT_ERROR, "negative (or overflowed) string size");
+ }
mrb_str_modify(mrb, s);
slen = RSTR_LEN(s);
if (len != slen) {