diff options
author | Kazuki Yamaguchi <[email protected]> | 2025-04-16 23:51:21 +0900 |
---|---|---|
committer | git <[email protected]> | 2025-04-16 15:16:50 +0000 |
commit | 0a8a641d0a1917285cbfeca0dc47f7bd56c1f093 (patch) | |
tree | ae0bfcaf2bd3d48e75c200d50561fec8283fa983 | |
parent | bbf873521a01c1c44297b9dd52cf4e309ae5b496 (diff) |
[ruby/openssl] ssl: fix SSLSocket#syswrite with String-convertible objects
Correctly pass the new object assigned by StringValue() to
ossl_ssl_write_internal_safe().
This is a follow-up to commit https://github.com/ruby/openssl/commit/0d8c17aa855d (Reduce
OpenSSL::Buffering#do_write overhead, 2024-12-21).
https://github.com/ruby/openssl/commit/3ff096196a
-rw-r--r-- | ext/openssl/ossl_ssl.c | 9 | ||||
-rw-r--r-- | test/openssl/test_ssl.rb | 5 |
2 files changed, 9 insertions, 5 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index db44c423f2..a5b25e14de 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -2080,14 +2080,13 @@ ossl_ssl_write_internal_safe(VALUE _args) static VALUE ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts) { - VALUE args[3] = {self, str, opts}; - int state; - str = StringValue(str); - + StringValue(str); int frozen = RB_OBJ_FROZEN(str); if (!frozen) { - str = rb_str_locktmp(str); + rb_str_locktmp(str); } + int state; + VALUE args[3] = {self, str, opts}; VALUE result = rb_protect(ossl_ssl_write_internal_safe, (VALUE)args, &state); if (!frozen) { rb_str_unlocktmp(str); diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index f1ce0b5dfc..4642063f45 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -270,6 +270,11 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase ssl.syswrite(str) assert_same buf, ssl.sysread(str.size, buf) assert_equal(str, buf) + + obj = Object.new + obj.define_singleton_method(:to_str) { str } + ssl.syswrite(obj) + assert_equal(str, ssl.sysread(str.bytesize)) } } end |