Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SEGV when parse with invalid content #1146

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ext/rbs_extension/parserstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ VALUE comment_to_ruby(comment *com, VALUE buffer) {
parserstate *alloc_parser(VALUE buffer, int start_pos, int end_pos, VALUE variables) {
VALUE string = rb_funcall(buffer, rb_intern("content"), 0);

StringValue(string);

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

def test_type_error
buffer = RBS::Buffer.new(content: 1, name: nil)
assert_raises TypeError do
RBS::Parser.parse_signature(buffer)
end
end

def test_interface_alias
RBS::Parser.parse_signature(buffer(<<-RBS)).tap do |decls|
interface _Foo[unchecked in A]
Expand Down