aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2024-05-05 16:59:54 +0900
committerGitHub <noreply@github.com>2024-05-05 16:59:54 +0900
commitd2d6a9923fd3687280c7830f907d94069950c01e (patch)
tree5c0d25774575348bd1c6d10d8290d0e7d324a171
parent97305cfafc4e06c67e8b2d96fd72acc83597db05 (diff)
parent08452993d6834352b0227f3368ee9144239e9803 (diff)
downloadruby-openssl-d2d6a9923fd3687280c7830f907d94069950c01e.tar.gz
Merge pull request #739 from casperisfine/read-clear-buffer
read: don't clear buffer when nothing can be read
-rw-r--r--ext/openssl/ossl_ssl.c8
-rw-r--r--test/openssl/test_pair.rb9
2 files changed, 12 insertions, 5 deletions
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 9f374b65..d68c64d5 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1958,9 +1958,11 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
else
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
}
- rb_str_set_len(str, 0);
- if (ilen == 0)
- return str;
+
+ if (ilen == 0) {
+ rb_str_set_len(str, 0);
+ return str;
+ }
VALUE io = rb_attr_get(self, id_i_io);
diff --git a/test/openssl/test_pair.rb b/test/openssl/test_pair.rb
index b6168839..66e36a7a 100644
--- a/test/openssl/test_pair.rb
+++ b/test/openssl/test_pair.rb
@@ -250,12 +250,17 @@ module OpenSSL::TestPairM
buf = +"garbage"
assert_equal :wait_readable, s2.read_nonblock(100, buf, exception: false)
- assert_equal "", buf
+ assert_equal "garbage", buf
s1.close
buf = +"garbage"
- assert_equal nil, s2.read(100, buf)
+ assert_nil s2.read(100, buf)
assert_equal "", buf
+
+ buf = +"garbage"
+ ret = s2.read(0, buf)
+ assert_same buf, ret
+ assert_equal "", ret
}
end