aboutsummaryrefslogtreecommitdiffstats
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-06 08:44:17 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-06 08:44:17 +0000
commit7efe9c97e2a1e5d0527d3c8cbbb85f6a683df63a (patch)
treefc2de898f24c0ca3e86b674180de13ca20ab10a9 /string.c
parentf893dd627503f1acc09a9424f83c6bde7795998e (diff)
downloadruby-7efe9c97e2a1e5d0527d3c8cbbb85f6a683df63a.tar.gz
string.c: out-of-bounds access
* string.c (rb_str_enumerate_lines): fix out-of-bounds access when record separator is longer than the last element. [Bug #14257] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/string.c b/string.c
index b7ae7069f6..75db0d22e8 100644
--- a/string.c
+++ b/string.c
@@ -8026,7 +8026,8 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, VALUE ary)
if (rsnewline) {
pend = chomp_newline(subptr, pend, enc);
}
- else if (memcmp(pend - rslen, rsptr, rslen) == 0) {
+ else if (pend - subptr >= rslen &&
+ memcmp(pend - rslen, rsptr, rslen) == 0) {
pend -= rslen;
}
}