mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	Fix keyword argument separation issues in OpenSSL::SSL::SSLSocket#sys{read,write}_nonblock
It's unlikely anyone would actually hit these. The methods are private, you only hit this code path if calling these methods before performing the SSL connection, and there is already a verbose warning issued.
This commit is contained in:
		
							parent
							
								
									760893d2f8
								
							
						
					
					
						commit
						3959469f24
					
				
				
				Notes:
				
					git
				
				2019-09-27 00:02:33 +09:00 
				
			
			
			
		
		
					 2 changed files with 28 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -1881,8 +1881,13 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
 | 
			
		|||
	ID meth = nonblock ? rb_intern("read_nonblock") : rb_intern("sysread");
 | 
			
		||||
 | 
			
		||||
	rb_warning("SSL session is not started yet.");
 | 
			
		||||
	if (nonblock)
 | 
			
		||||
	    return rb_funcall(io, meth, 3, len, str, opts);
 | 
			
		||||
	if (nonblock) {
 | 
			
		||||
            VALUE argv[3];
 | 
			
		||||
            argv[0] = len;
 | 
			
		||||
            argv[1] = str;
 | 
			
		||||
            argv[2] = opts;
 | 
			
		||||
            return rb_funcallv_kw(io, meth, 3, argv, RB_PASS_KEYWORDS);
 | 
			
		||||
        }
 | 
			
		||||
	else
 | 
			
		||||
	    return rb_funcall(io, meth, 2, len, str);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1972,8 +1977,12 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
 | 
			
		|||
	    rb_intern("write_nonblock") : rb_intern("syswrite");
 | 
			
		||||
 | 
			
		||||
	rb_warning("SSL session is not started yet.");
 | 
			
		||||
	if (nonblock)
 | 
			
		||||
	    return rb_funcall(io, meth, 2, str, opts);
 | 
			
		||||
	if (nonblock) {
 | 
			
		||||
            VALUE argv[2];
 | 
			
		||||
            argv[0] = str;
 | 
			
		||||
            argv[1] = opts;
 | 
			
		||||
            return rb_funcallv_kw(io, meth, 2, argv, RB_PASS_KEYWORDS);
 | 
			
		||||
        }
 | 
			
		||||
	else
 | 
			
		||||
	    return rb_funcall(io, meth, 1, str);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -155,6 +155,21 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase
 | 
			
		|||
    }
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sysread_nonblock_and_syswrite_nonblock_keywords
 | 
			
		||||
    start_server(ignore_listener_error: true) do |port|
 | 
			
		||||
      sock = TCPSocket.new("127.0.0.1", port)
 | 
			
		||||
      ssl = OpenSSL::SSL::SSLSocket.new(sock)
 | 
			
		||||
 | 
			
		||||
      assert_warn ("") do
 | 
			
		||||
        ssl.send(:syswrite_nonblock, "1", exception: false)
 | 
			
		||||
        ssl.send(:sysread_nonblock, 1, exception: false) rescue nil
 | 
			
		||||
        ssl.send(:sysread_nonblock, 1, String.new, exception: false) rescue nil
 | 
			
		||||
      end
 | 
			
		||||
    ensure
 | 
			
		||||
      sock&.close
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def test_sync_close
 | 
			
		||||
    start_server { |port|
 | 
			
		||||
      begin
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue