Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read: don't clear buffer when nothing can be read #739

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/openssl/ossl_ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 7 additions & 2 deletions test/openssl/test_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,17 @@ def test_read_with_outbuf

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

Expand Down