Bug #13935 » ruby_2_3-0003-ssl-prevent-SSLSocket-sysread-from-leaking-uninitial.patch
ext/openssl/ossl_ssl.c | ||
---|---|---|
}
|
||
ilen = NUM2INT(len);
|
||
if(NIL_P(str)) str = rb_str_new(0, ilen);
|
||
else{
|
||
StringValue(str);
|
||
rb_str_modify(str);
|
||
rb_str_resize(str, ilen);
|
||
if (NIL_P(str))
|
||
str = rb_str_new(0, ilen);
|
||
else {
|
||
StringValue(str);
|
||
if (RSTRING_LEN(str) >= ilen)
|
||
rb_str_modify(str);
|
||
else
|
||
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
|
||
}
|
||
if(ilen == 0) return str;
|
||
OBJ_TAINT(str);
|
||
rb_str_set_len(str, 0);
|
||
if (ilen == 0)
|
||
return str;
|
||
GetSSL(self, ssl);
|
||
GetOpenFile(ossl_ssl_get_io(self), fptr);
|
||
if (ssl) {
|
||
for (;;){
|
||
nread = SSL_read(ssl, RSTRING_PTR(str), RSTRING_LENINT(str));
|
||
nread = SSL_read(ssl, RSTRING_PTR(str), ilen);
|
||
switch(ssl_get_error(ssl, nread)){
|
||
case SSL_ERROR_NONE:
|
||
goto end;
|
||
... | ... | |
end:
|
||
rb_str_set_len(str, nread);
|
||
OBJ_TAINT(str);
|
||
return str;
|
||
}
|
||
test/openssl/test_pair.rb | ||
---|---|---|
}
|
||
end
|
||
def test_read_with_outbuf
|
||
ssl_pair { |s1, s2|
|
||
s1.write("abc\n")
|
||
buf = ""
|
||
ret = s2.read(2, buf)
|
||
assert_same ret, buf
|
||
assert_equal "ab", ret
|
||
buf = "garbage"
|
||
ret = s2.read(2, buf)
|
||
assert_same ret, buf
|
||
assert_equal "c\n", ret
|
||
buf = "garbage"
|
||
assert_equal :wait_readable, s2.read_nonblock(100, buf, exception: false)
|
||
assert_equal "", buf
|
||
s1.close
|
||
buf = "garbage"
|
||
assert_equal nil, s2.read(100, buf)
|
||
assert_equal "", buf
|
||
}
|
||
end
|
||
def write_nonblock(socket, meth, str)
|
||
ret = socket.send(meth, str)
|
||
ret.is_a?(Symbol) ? 0 : ret
|