Skip to content
Permalink
Browse files
Fixed memory disclosure in String#lines
Reported from from Alex Snaps via Mathieu Leduc-Hamel,
both from shopify.com.  Thank you!
  • Loading branch information
matz committed Nov 15, 2016
1 parent 92f72c7 commit 242b21947102d98aba2fa3db2725b129ca547f20
Showing 1 changed file with 9 additions and 2 deletions.
@@ -307,8 +307,9 @@ mrb_str_lines(mrb_state *mrb, mrb_value self)
int ai;
mrb_int len;
mrb_value arg;
char *p = RSTRING_PTR(self), *t;
char *e = p + RSTRING_LEN(self);
char *b = RSTRING_PTR(self);
char *p = b, *t;
char *e = b + RSTRING_LEN(self);

mrb_get_args(mrb, "&", &blk);

@@ -322,6 +323,12 @@ mrb_str_lines(mrb_state *mrb, mrb_value self)
len = (mrb_int) (p - t);
arg = mrb_str_new(mrb, t, len);
mrb_yield_argv(mrb, blk, 1, &arg);
if (b != RSTRING_PTR(self)) {
ptrdiff_t diff = p - b;
b = RSTRING_PTR(self);
p = b + diff;
}
e = b + RSTRING_LEN(self);
}
return self;
}

0 comments on commit 242b219

Please sign in to comment.