From 6003df221ef6e91f259a15b0d264378f6dfbb6b1 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Tue, 10 Sep 2013 21:39:30 +0100 Subject: [PATCH] fix error handling on SSL handles --- src/stream/read.c | 5 ++--- src/stream/write.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/stream/read.c b/src/stream/read.c index 2555655..9b697f5 100644 --- a/src/stream/read.c +++ b/src/stream/read.c @@ -20,12 +20,11 @@ * along with this program. If not, see . */ +#include #include #include #include -#include - #include "stream.h" #include "logger.h" @@ -67,7 +66,7 @@ streamRead(Stream this, void * buf, size_t count) case STREAM_SSL: done = SSL_read((this->handle).ssl, buf, count); - if (0 > done) { + if (0 >= done) { switch (SSL_get_error((this->handle).ssl, done)) { case SSL_ERROR_SSL: case SSL_ERROR_SYSCALL: diff --git a/src/stream/write.c b/src/stream/write.c index 5e9b346..f8e5899 100644 --- a/src/stream/write.c +++ b/src/stream/write.c @@ -20,11 +20,16 @@ * along with this program. If not, see . */ +#include #include #include #include #include "stream.h" +#include "logger.h" + +extern Logger logger; + ssize_t streamWrite(Stream this, void * buf, size_t count) @@ -59,6 +64,29 @@ streamWrite(Stream this, void * buf, size_t count) case STREAM_SSL: done = SSL_write((this->handle).ssl, buf, count); + + if (0 >= done) { + switch (SSL_get_error((this->handle).ssl, done)) { + case SSL_ERROR_SSL: + case SSL_ERROR_SYSCALL: + { + unsigned long err; + + while (0 != (err = ERR_get_error())) { + loggerLog( + logger, + LOGGER_DEBUG, + ERR_error_string(err, NULL)); + } + } + // DROP THROUGH + + case SSL_ERROR_ZERO_RETURN: + done = -2; + break; + } + } + break; default: