]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-ssl-iostream: Return stacked errors as single combined string.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 21 Apr 2016 18:45:02 +0000 (21:45 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 22 Apr 2016 22:40:48 +0000 (01:40 +0300)
Instead of logging stacked errors as separate log lines, which don't provide
any context of what created them.

src/lib-ssl-iostream/iostream-openssl-common.c

index 572689763d770f450d3a5318fc848a7c978a0d59..439ccfd08c7acfd5c7a88503ea4cca7b38369301 100644 (file)
@@ -1,6 +1,7 @@
 /* Copyright (c) 2009-2016 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "str.h"
 #include "iostream-openssl.h"
 
 #include <openssl/x509v3.h>
@@ -185,8 +186,9 @@ static const char *ssl_err2str(unsigned long err, const char *data, int flags)
 
 const char *openssl_iostream_error(void)
 {
+       string_t *errstr = NULL;
        unsigned long err;
-       const char *data;
+       const char *data, *final_error;
        int flags;
 
        while ((err = ERR_get_error_line_data(NULL, NULL, &data, &flags)) != 0) {
@@ -194,15 +196,26 @@ const char *openssl_iostream_error(void)
                        i_fatal_status(FATAL_OUTOFMEM, "OpenSSL malloc() failed");
                if (ERR_peek_error() == 0)
                        break;
-               i_error("SSL: Stacked error: %s",
-                       ssl_err2str(err, data, flags));
+               if (errstr == NULL)
+                       errstr = t_str_new(128);
+               else
+                       str_append(errstr, ", ");
+               str_append(errstr, ssl_err2str(err, data, flags));
        }
        if (err == 0) {
                if (errno != 0)
-                       return strerror(errno);
-               return "Unknown error";
+                       final_error = strerror(errno);
+               else
+                       final_error = "Unknown error";
+       } else {
+               final_error = ssl_err2str(err, data, flags);
+       }
+       if (errstr == NULL)
+               return final_error;
+       else {
+               str_printfa(errstr, ", %s", final_error);
+               return str_c(errstr);
        }
-       return ssl_err2str(err, data, flags);
 }
 
 const char *openssl_iostream_key_load_error(void)