Skip to content

Commit 201a5d3

Browse files
authored
Merge pull request #881 from rhenium/ky/ssl-syswrite-to_str
ssl: fix SSLSocket#syswrite with String-convertible objects
2 parents b3de125 + 3ff0961 commit 201a5d3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ext/openssl/ossl_ssl.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,14 +2080,13 @@ ossl_ssl_write_internal_safe(VALUE _args)
20802080
static VALUE
20812081
ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
20822082
{
2083-
VALUE args[3] = {self, str, opts};
2084-
int state;
2085-
str = StringValue(str);
2086-
2083+
StringValue(str);
20872084
int frozen = RB_OBJ_FROZEN(str);
20882085
if (!frozen) {
2089-
str = rb_str_locktmp(str);
2086+
rb_str_locktmp(str);
20902087
}
2088+
int state;
2089+
VALUE args[3] = {self, str, opts};
20912090
VALUE result = rb_protect(ossl_ssl_write_internal_safe, (VALUE)args, &state);
20922091
if (!frozen) {
20932092
rb_str_unlocktmp(str);

test/openssl/test_ssl.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,11 @@ def test_sysread_and_syswrite
270270
ssl.syswrite(str)
271271
assert_same buf, ssl.sysread(str.size, buf)
272272
assert_equal(str, buf)
273+
274+
obj = Object.new
275+
obj.define_singleton_method(:to_str) { str }
276+
ssl.syswrite(obj)
277+
assert_equal(str, ssl.sysread(str.bytesize))
273278
}
274279
}
275280
end

0 commit comments

Comments
 (0)