ruby-changes:69768
From: Samuel <ko1@a...>
Date: Wed, 17 Nov 2021 06:40:04 +0900 (JST)
Subject: [ruby-changes:69768] 5190926e40 (master): Validate string type when constructing IO::Buffer for string mapping.
https://git.ruby-lang.org/ruby.git/commit/?id=5190926e40 From 5190926e40febeeb3822b8bd7c031b06279dc3f1 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Mon, 15 Nov 2021 15:28:02 +1300 Subject: Validate string type when constructing IO::Buffer for string mapping. --- io_buffer.c | 2 ++ test/ruby/test_io_buffer.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/io_buffer.c b/io_buffer.c index 45dbfd02da3..bd902ed8d44 100644 --- a/io_buffer.c +++ b/io_buffer.c @@ -259,6 +259,8 @@ rb_io_buffer_type_allocate(VALUE self) https://github.com/ruby/ruby/blob/trunk/io_buffer.c#L259 VALUE rb_io_buffer_type_for(VALUE klass, VALUE string) { + StringValue(string); + VALUE instance = rb_io_buffer_type_allocate(klass); struct rb_io_buffer *data = NULL; diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 12937729f4e..57d1867b25c 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -81,6 +81,14 @@ class TestIOBuffer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_buffer.rb#L81 assert_equal "Hello World", string end + def test_non_string + not_string = Object.new + + assert_raise TypeError do + IO::Buffer.for(not_string) + end + end + def test_resize buffer = IO::Buffer.new(1024, IO::Buffer::MAPPED) buffer.resize(2048, 0) -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/