mirror of
https://github.com/ruby/ruby.git
synced 2025-09-15 16:44:01 +02:00
[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 commit0d8c17aa85
(Reduce OpenSSL::Buffering#do_write overhead, 2024-12-21).3ff096196a
This commit is contained in:
parent
bbf873521a
commit
0a8a641d0a
2 changed files with 9 additions and 5 deletions
|
@ -2080,14 +2080,13 @@ ossl_ssl_write_internal_safe(VALUE _args)
|
||||||
static VALUE
|
static VALUE
|
||||||
ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
|
ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
|
||||||
{
|
{
|
||||||
VALUE args[3] = {self, str, opts};
|
StringValue(str);
|
||||||
int state;
|
|
||||||
str = StringValue(str);
|
|
||||||
|
|
||||||
int frozen = RB_OBJ_FROZEN(str);
|
int frozen = RB_OBJ_FROZEN(str);
|
||||||
if (!frozen) {
|
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);
|
VALUE result = rb_protect(ossl_ssl_write_internal_safe, (VALUE)args, &state);
|
||||||
if (!frozen) {
|
if (!frozen) {
|
||||||
rb_str_unlocktmp(str);
|
rb_str_unlocktmp(str);
|
||||||
|
|
|
@ -270,6 +270,11 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
|
||||||
ssl.syswrite(str)
|
ssl.syswrite(str)
|
||||||
assert_same buf, ssl.sysread(str.size, buf)
|
assert_same buf, ssl.sysread(str.size, buf)
|
||||||
assert_equal(str, 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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue