summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2016-12-31 23:33:34 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2016-12-31 23:33:34 +0900
commit1ed4de58d016a25d8a6ae4576e447dab1709535c (patch)
treee3e349b3dd96c8d8a1c2766f0655c152a2ed52d9 /src
parent342b1de65c5f044e1f3dc08b6e04c9cd0206abc3 (diff)
downloadmruby-1ed4de58d016a25d8a6ae4576e447dab1709535c.tar.gz
mruby-1ed4de58d016a25d8a6ae4576e447dab1709535c.zip
str_buf_cat(): better size check added; ref #3342
Diffstat (limited to 'src')
-rw-r--r--src/string.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/string.c b/src/string.c
index d41237f44..072bf2226 100644
--- a/src/string.c
+++ b/src/string.c
@@ -163,15 +163,20 @@ str_buf_cat(mrb_state *mrb, struct RString *s, const char *ptr, size_t len)
total = RSTR_LEN(s)+len;
if (total >= MRB_INT_MAX) {
+ size_error:
mrb_raise(mrb, E_ARGUMENT_ERROR, "string size too big");
}
if (capa <= total) {
while (total > capa) {
- if (capa + 1 >= MRB_INT_MAX / 2) {
- capa = MRB_INT_MAX;
- break;
+ if (capa <= MRB_INT_MAX / 2) {
+ capa *= 2;
+ }
+ else {
+ goto size_error;
}
- capa = (capa + 1) * 2;
+ }
+ if (capa < total || capa > MRB_INT_MAX) {
+ goto size_error;
}
resize_capa(mrb, s, capa);
}