Skip to content

Commit

Permalink
str_buf_cat(): better size check added; ref #3342
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Dec 31, 2016
1 parent 342b1de commit 1ed4de5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 1ed4de5

Please sign in to comment.