[PRISM] Fix crash in compile_prism

If the argument is not a file or a string, it assumes it's a string
which will crash because RSTRING_PTR and RSTRING_LEN assumes it's a
string.
This commit is contained in:
Peter Zhu 2024-01-17 11:50:40 -05:00
parent b0a32b7249
commit a6e924cf5f
2 changed files with 7 additions and 0 deletions

1
iseq.c
View File

@ -1485,6 +1485,7 @@ iseqw_s_compile_prism(int argc, VALUE *argv, VALUE self)
pm_string_mapped_init(&input, RSTRING_PTR(file));
}
else {
Check_Type(src, T_STRING);
input.source = (const uint8_t *)RSTRING_PTR(src);
input.length = RSTRING_LEN(src);
input.type = PM_STRING_SHARED;

View File

@ -809,4 +809,10 @@ class TestISeq < Test::Unit::TestCase
end
end
end
def test_compile_prism_with_invalid_object_type
assert_raise(TypeError) do
RubyVM::InstructionSequence.compile_prism(Object.new)
end
end
end