Skip to content

Commit e4ec598

Browse files
authored
Merge pull request #3227 from ruby/pz-regexp-uninit-val
Fix use of uninitialized value when parsing regexp
2 parents ed36c4a + be6cbc2 commit e4ec598

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/regexp.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ pm_regexp_parse_range_quantifier(pm_regexp_parser_t *parser) {
158158
} state = PM_REGEXP_RANGE_QUANTIFIER_STATE_START;
159159

160160
while (1) {
161+
if (parser->cursor >= parser->end) {
162+
parser->cursor = savepoint;
163+
return true;
164+
}
165+
161166
switch (state) {
162167
case PM_REGEXP_RANGE_QUANTIFIER_STATE_START:
163168
switch (*parser->cursor) {

test/prism/regexp_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def test_fake_range_quantifier_because_of_spaces
186186
assert_valid_regexp("foo{1, 2}")
187187
end
188188

189+
def test_fake_range_quantifier_because_unclosed
190+
assert_valid_regexp("\\A{")
191+
end
192+
189193
############################################################################
190194
# These test that flag values are correct.
191195
############################################################################

0 commit comments

Comments
 (0)