aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
diff options
context:
space:
mode:
Diffstat (limited to 'ext/openssl')
-rw-r--r--ext/openssl/ossl.c31
-rw-r--r--ext/openssl/ossl.h1
-rw-r--r--ext/openssl/ossl_ssl.c10
3 files changed, 32 insertions, 10 deletions
diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
index 28696cabe2..d4a2dc1276 100644
--- a/ext/openssl/ossl.c
+++ b/ext/openssl/ossl.c
@@ -272,10 +272,9 @@ ossl_to_der_if_possible(VALUE obj)
/*
* Errors
*/
-void
-ossl_raise(VALUE exc, const char *fmt, ...)
+static VALUE
+ossl_make_error(VALUE exc, const char *fmt, va_list args)
{
- va_list args;
char buf[BUFSIZ];
const char *msg;
long e;
@@ -287,9 +286,7 @@ ossl_raise(VALUE exc, const char *fmt, ...)
e = ERR_peek_error();
#endif
if (fmt) {
- va_start(args, fmt);
len = vsnprintf(buf, BUFSIZ, fmt, args);
- va_end(args);
}
if (len < BUFSIZ && e) {
if (dOSSL == Qtrue) /* FULL INFO */
@@ -306,7 +303,29 @@ ossl_raise(VALUE exc, const char *fmt, ...)
ERR_clear_error();
if(len > BUFSIZ) len = strlen(buf);
- rb_exc_raise(rb_exc_new(exc, buf, len));
+ return rb_exc_new(exc, buf, len);
+}
+
+void
+ossl_raise(VALUE exc, const char *fmt, ...)
+{
+ va_list args;
+ VALUE err;
+ va_start(args, fmt);
+ err = ossl_make_error(exc, fmt, args);
+ va_end(args);
+ rb_exc_raise(err);
+}
+
+VALUE
+ossl_exc_new(VALUE exc, const char *fmt, ...)
+{
+ va_list args;
+ VALUE err;
+ va_start(args, fmt);
+ err = ossl_make_error(exc, fmt, args);
+ va_end(args);
+ return err;
}
/*
diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
index e40c93b608..9ac1525085 100644
--- a/ext/openssl/ossl.h
+++ b/ext/openssl/ossl.h
@@ -135,6 +135,7 @@ int ossl_pem_passwd_cb(char *, int, int, void *);
*/
#define OSSL_ErrMsg() ERR_reason_error_string(ERR_get_error())
NORETURN(void ossl_raise(VALUE, const char *, ...));
+VALUE ossl_exc_new(VALUE, const char *, ...);
/*
* Verify callback
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 767f81e54e..61b30d3afb 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1114,15 +1114,17 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
rb_eof_error();
case SSL_ERROR_WANT_WRITE:
if (nonblock) {
- errno = EWOULDBLOCK;
- rb_sys_fail("SSL_ERROR_WANT_WRITE");
+ VALUE exc = ossl_exc_new(eSSLError, "write would block");
+ rb_extend_object(exc, rb_mWaitWritable);
+ rb_exc_raise(exc);
}
rb_io_wait_writable(FPTR_TO_FD(fptr));
continue;
case SSL_ERROR_WANT_READ:
if (nonblock) {
- errno = EWOULDBLOCK;
- rb_sys_fail("SSL_ERROR_WANT_READ");
+ VALUE exc = ossl_exc_new(eSSLError, "read would block");
+ rb_extend_object(exc, rb_mWaitReadable);
+ rb_exc_raise(exc);
}
rb_io_wait_readable(FPTR_TO_FD(fptr));
continue;