Commit 2bb30481 authored by dearblue's avatar dearblue

Fix heap buffer overflow; ref #4549

This patch is showed in #4549.
parent 93b3b83c
...@@ -1184,7 +1184,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb ...@@ -1184,7 +1184,7 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
mrb_str_modify(mrb, str); mrb_str_modify(mrb, str);
if (len < newlen || len - newlen >= shrink_threshold) { if (len < newlen) {
resize_capa(mrb, str, newlen); resize_capa(mrb, str, newlen);
} }
...@@ -1197,6 +1197,10 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb ...@@ -1197,6 +1197,10 @@ str_replace_partial(mrb_state *mrb, mrb_value src, mrb_int pos, mrb_int end, mrb
RSTR_SET_LEN(str, newlen); RSTR_SET_LEN(str, newlen);
strp[newlen] = '\0'; strp[newlen] = '\0';
if (len - newlen >= shrink_threshold) {
resize_capa(mrb, str, newlen);
}
return src; return src;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment