aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl/ossl_bio.c
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2017-08-08 18:37:31 +0900
committerKazuki Yamaguchi <k@rhe.jp>2017-08-08 18:39:38 +0900
commit3ed3fc5dde962615fcf42d0cfa4feba6cb8af9d5 (patch)
treef40255ea6be7f6c060f4de1a4c2d999ab716453c /ext/openssl/ossl_bio.c
parentd4ded26d4507b36c7364f68635c0c00f37f740ba (diff)
parentdf37b7a22eb0c70ddba4722630662b4c1e73b009 (diff)
downloadruby-openssl-3ed3fc5dde962615fcf42d0cfa4feba6cb8af9d5.tar.gz
Merge branch 'maint'
* maint: Ruby/OpenSSL 2.0.5 ssl: fix compile error with OpenSSL 1.0.0 ssl: remove unsupported TLS versions from SSLContext::METHODS Add msys2 library dependency tag in gem metadata ossl_pem_passwd_cb: handle nil from the block explicitly ossl_pem_passwd_cb: do not check for taintedness ossl_pem_passwd_cb: relax passphrase length constraint appveyor.yml: test against Ruby 2.4 Rakefile: install_dependencies: install only when needed bio: do not use the FILE BIO method in ossl_obj2bio() bio: prevent possible GC issue in ossl_obj2bio() test/test_ssl: allow 3DES cipher suites in test_sslctx_set_params
Diffstat (limited to 'ext/openssl/ossl_bio.c')
-rw-r--r--ext/openssl/ossl_bio.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/ext/openssl/ossl_bio.c b/ext/openssl/ossl_bio.c
index 5f3f65a5..42833d90 100644
--- a/ext/openssl/ossl_bio.c
+++ b/ext/openssl/ossl_bio.c
@@ -10,37 +10,18 @@
#include "ossl.h"
BIO *
-ossl_obj2bio(VALUE obj)
+ossl_obj2bio(volatile VALUE *pobj)
{
+ VALUE obj = *pobj;
BIO *bio;
- if (RB_TYPE_P(obj, T_FILE)) {
- rb_io_t *fptr;
- FILE *fp;
- int fd;
-
- GetOpenFile(obj, fptr);
- rb_io_check_readable(fptr);
- if ((fd = rb_cloexec_dup(fptr->fd)) < 0){
- rb_sys_fail(0);
- }
- rb_update_max_fd(fd);
- if (!(fp = fdopen(fd, "r"))){
- int e = errno;
- close(fd);
- rb_syserr_fail(e, 0);
- }
- if (!(bio = BIO_new_fp(fp, BIO_CLOSE))){
- fclose(fp);
- ossl_raise(eOSSLError, NULL);
- }
- }
- else {
- StringValue(obj);
- bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
- if (!bio) ossl_raise(eOSSLError, NULL);
- }
-
+ if (RB_TYPE_P(obj, T_FILE))
+ obj = rb_funcallv(obj, rb_intern("read"), 0, NULL);
+ StringValue(obj);
+ bio = BIO_new_mem_buf(RSTRING_PTR(obj), RSTRING_LENINT(obj));
+ if (!bio)
+ ossl_raise(eOSSLError, "BIO_new_mem_buf");
+ *pobj = obj;
return bio;
}