aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-07 05:48:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-03-07 05:48:15 +0000
commit86763d64481548b23196f39d4df321f12c1c3681 (patch)
tree43c1dfd4d2c94e5f24c67dab03fe74a0b89d748e /string.c
parentc0d401ef34981d14a2b18fa18a97cc5f6d39de07 (diff)
downloadruby-86763d64481548b23196f39d4df321f12c1c3681.tar.gz
string.c: fix integer overflow
* string.c (rb_str_subpos): fix integer overflow which can happen only when SHARABLE_MIDDLE_SUBSTRING is enabled. incorpolate https://github.com/mruby/mruby/commit/7db0786abdd243ba031e24683f git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57797 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/string.c b/string.c
index e239a27a4c..4968e86d74 100644
--- a/string.c
+++ b/string.c
@@ -2386,7 +2386,7 @@ rb_str_subpos(VALUE str, long beg, long *lenp)
beg += blen;
if (beg < 0) return 0;
}
- if (beg + len > blen)
+ if (len > blen - beg)
len = blen - beg;
if (len < 0) return 0;
p = s + beg;