summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-pack/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-05-16 10:13:52 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2019-05-16 10:13:52 +0900
commit2f1425414226f4ff6698de99b0d1b743368cdb39 (patch)
tree4736156cc5e2d0abcb1b8590af5bd3353f332e2c /mrbgems/mruby-pack/src
parent752edf413f09fb3e78d79ca7d752ae5dc2e25c02 (diff)
downloadmruby-2f1425414226f4ff6698de99b0d1b743368cdb39.tar.gz
mruby-2f1425414226f4ff6698de99b0d1b743368cdb39.zip
Avoid potential integer overflow.
Diffstat (limited to 'mrbgems/mruby-pack/src')
-rw-r--r--mrbgems/mruby-pack/src/pack.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/mrbgems/mruby-pack/src/pack.c b/mrbgems/mruby-pack/src/pack.c
index ac29fdbf3..0c4f0d965 100644
--- a/mrbgems/mruby-pack/src/pack.c
+++ b/mrbgems/mruby-pack/src/pack.c
@@ -1075,10 +1075,11 @@ alias:
if (ISDIGIT(ch)) {
count = ch - '0';
while (tmpl->idx < tlen && ISDIGIT(tptr[tmpl->idx])) {
- count = count * 10 + (tptr[tmpl->idx++] - '0');
- if (count < 0) {
+ int ch = tptr[tmpl->idx++] - '0';
+ if (count+ch > INT_MAX/10) {
mrb_raise(mrb, E_RUNTIME_ERROR, "too big template length");
}
+ count = count * 10 + ch;
}
continue; /* special case */
} else if (ch == '*') {