dumping ground for random patches and texts
 help / color / mirror / Atom feed
* [PATCH] ext/openssl/ossl_ssl.c: raise if kwargs given in blocking mode
@ 2015-06-24 17:29 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-06-24 17:29 UTC (permalink / raw)
  To: spew

OpenSSL::SSL::SSLSocket#sysread does not accept kwargs in blocking
mode, inform users if they make an error.

* ext/openssl/ossl_ssl.c (ossl_ssl_read_internal):
  do not process kwargs in blocking mode
* test/openssl/test_ssl.rb: test sysread
---
 ext/openssl/ossl_ssl.c   | 10 +++++++---
 test/openssl/test_ssl.rb | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index ce8ce89..4496d46 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1430,13 +1430,17 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
 {
     SSL *ssl;
     int ilen, nread = 0;
-    int no_exception;
+    int no_exception = 0;
     VALUE len, str;
     rb_io_t *fptr;
     VALUE opts = Qnil;
 
-    rb_scan_args(argc, argv, "11:", &len, &str, &opts);
-    no_exception = get_no_exception(opts);
+    if (nonblock) {
+	rb_scan_args(argc, argv, "11:", &len, &str, &opts);
+	no_exception = get_no_exception(opts);
+    } else {
+	rb_scan_args(argc, argv, "11", &len, &str);
+    }
 
     ilen = NUM2INT(len);
     if(NIL_P(str)) str = rb_str_new(0, ilen);
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index 3ffddf8..f2a64ca 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -60,6 +60,20 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
     }
   end
 
+  def test_ssl_sysread_blocking_error
+    start_server(OpenSSL::SSL::VERIFY_NONE, true) { |server, port|
+      server_connect(port) { |ssl|
+        ssl.write("abc\n")
+        assert_raise(TypeError) { ssl.sysread(4, exception: false) }
+        buf = ''
+        assert_raise(ArgumentError) { ssl.sysread(4, buf, exception: false) }
+        assert_equal '', buf
+        assert_equal buf.object_id, ssl.sysread(4, buf).object_id
+        assert_equal "abc\n", buf
+      }
+    }
+  end
+
   def test_connect_and_close
     start_server(OpenSSL::SSL::VERIFY_NONE, true){|server, port|
       sock = TCPSocket.new("127.0.0.1", port)
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-24 17:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24 17:29 [PATCH] ext/openssl/ossl_ssl.c: raise if kwargs given in blocking mode Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).