From a90b20cfb6fa5332dd8a4335b16a171feaf5a3a1 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Fri, 15 Feb 2002 03:52:22 +0000 Subject: Minor fixes for 5.9.8. svn path=/trunk/; revision=3578 --- socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'socket.c') diff --git a/socket.c b/socket.c index 2631e1fb..ceadc960 100644 --- a/socket.c +++ b/socket.c @@ -563,13 +563,14 @@ int SockRead(int sock, char *buf, int len) later change the behavior of SSL_peek to "fix" this problem... :-( */ if ((n = SSL_peek(ssl, bp, len)) < 0) { + (void)SSL_get_error(ssl, n); return(-1); } if( 0 == n ) { /* SSL_peek says no data... Does he mean no data or did the connection blow up? If we got an error then bail! */ - if( 0 != ( n = ERR_get_error() ) ) { + if( 0 != ( n = SSL_get_error(ssl, n) ) ) { return -1; } /* We didn't get an error so read at least one @@ -581,8 +582,13 @@ int SockRead(int sock, char *buf, int len) newline = NULL; } else if ((newline = memchr(bp, '\n', n)) != NULL) n = newline - bp + 1; - if ((n = SSL_read(ssl, bp, n)) == -1) { - return(-1); + /* Matthias Andree: SSL_read can return 0, in that case + * we must cal SSL_get_error to figure if there was + * an error or just a "no data" condition */ + if ((n = SSL_read(ssl, bp, n)) <= 0) { + if ((n = SSL_get_error(ssl, n))) { + return(-1); + } } /* Check for case where our single character turned out to * be a newline... (It wasn't going to get caught by @@ -635,16 +641,20 @@ int SockPeek(int sock) #ifdef SSL_ENABLE if( NULL != ( ssl = SSLGetContext( sock ) ) ) { n = SSL_peek(ssl, &ch, 1); + if (n < 0) { + (void)SSL_get_error(ssl, n); + return -1; + } if( 0 == n ) { /* This code really needs to implement a "hold back" * to simulate a functioning SSL_peek()... sigh... * Has to be coordinated with the read code above. * Next on the list todo... */ - /* SSL_peek says no data... Does he mean no data + /* SSL_peek says 0... Does that mean no data or did the connection blow up? If we got an error then bail! */ - if( 0 != ( n = ERR_get_error() ) ) { + if( 0 != ( n = SSL_get_error(ssl, n) ) ) { return -1; } -- cgit v1.2.3