Skip to content

Commit

Permalink
Fix SEGV with parse negative position
Browse files Browse the repository at this point in the history
  • Loading branch information
ksss committed Apr 5, 2024
1 parent 64afbf1 commit 8045046
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/rbs_extension/parserstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ parserstate *alloc_parser(VALUE buffer, int start_pos, int end_pos, VALUE variab

StringValue(string);

if (start_pos < 0 || end_pos < 0) {
rb_raise(rb_eArgError, "negative position range: %d...%d", start_pos, end_pos);
}

lexstate *lexer = calloc(1, sizeof(lexstate));
lexer->string = string;
lexer->current.line = 1;
Expand Down
6 changes: 6 additions & 0 deletions test/rbs/parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,12 @@ def test_buffer_location
end
end

def test_negative_range
assert_raises ArgumentError do
RBS::Parser.parse_type("a", range: -2...-1)
end
end

def test_parse_eof_nil
code = buffer("type1 ")

Expand Down

0 comments on commit 8045046

Please sign in to comment.