Avoid potential integer overflow.

parent 752edf41
...@@ -1075,10 +1075,11 @@ alias: ...@@ -1075,10 +1075,11 @@ alias:
if (ISDIGIT(ch)) { if (ISDIGIT(ch)) {
count = ch - '0'; count = ch - '0';
while (tmpl->idx < tlen && ISDIGIT(tptr[tmpl->idx])) { while (tmpl->idx < tlen && ISDIGIT(tptr[tmpl->idx])) {
count = count * 10 + (tptr[tmpl->idx++] - '0'); int ch = tptr[tmpl->idx++] - '0';
if (count < 0) { if (count+ch > INT_MAX/10) {
mrb_raise(mrb, E_RUNTIME_ERROR, "too big template length"); mrb_raise(mrb, E_RUNTIME_ERROR, "too big template length");
} }
count = count * 10 + ch;
} }
continue; /* special case */ continue; /* special case */
} else if (ch == '*') { } else if (ch == '*') {
......
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