[nginx] SSL: removed logging of empty "(SSL:)" in ngx_ssl_error().

Maxim Dounin mdounin at mdounin.ru
Mon Feb 25 13:49:37 UTC 2019


details:   https://hg.nginx.org/nginx/rev/982008fbc4ba
branches:  
changeset: 7459:982008fbc4ba
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon Feb 25 16:41:15 2019 +0300
description:
SSL: removed logging of empty "(SSL:)" in ngx_ssl_error().

The "(SSL:)" snippet currently appears in logs when nginx code uses
ngx_ssl_error() to log an error, but OpenSSL's error queue is empty.
This can happen either because the error wasn't in fact from OpenSSL,
or because OpenSSL did not indicate the error in the error queue
for some reason.

In particular, currently "(SSL:)" can be seen in errors at least in
the following cases:

- When SSL_write() fails due to a syscall error,
  "[info] ... SSL_write() failed (SSL:) (32: Broken pipe)...".

- When loading a certificate with no data in it,
  "[emerg] PEM_read_bio_X509_AUX(...) failed (SSL:)".
  This can easily happen due to an additional empty line before
  the end line, so all lines of the certificate are interpreted
  as header lines.

- When trying to configure an unknown curve,
  "[emerg] SSL_CTX_set1_curves_list("foo") failed (SSL:)".

Likely there are other cases as well.

With this change, "(SSL:...)" will be only added to the error message
if there is something in the error queue.  This is expected to make
logs more readable in the above cases.  Additionally, with this change
it is now possible to use ngx_ssl_error() to log errors when some
of the possible errors are not from OpenSSL and not expected to have
anything in the error queue.

diffstat:

 src/event/ngx_event_openssl.c |  70 +++++++++++++++++++++++-------------------
 1 files changed, 38 insertions(+), 32 deletions(-)

diffs (83 lines):

diff --git a/src/event/ngx_event_openssl.c b/src/event/ngx_event_openssl.c
--- a/src/event/ngx_event_openssl.c
+++ b/src/event/ngx_event_openssl.c
@@ -2743,41 +2743,47 @@ ngx_ssl_error(ngx_uint_t level, ngx_log_
     p = ngx_vslprintf(errstr, last - 1, fmt, args);
     va_end(args);
 
-    p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
-
-    for ( ;; ) {
-
-        n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);
-
-        if (n == 0) {
-            break;
-        }
-
-        /* ERR_error_string_n() requires at least one byte */
-
-        if (p >= last - 1) {
-            goto next;
+    if (ERR_peek_error()) {
+        p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
+
+        for ( ;; ) {
+
+            n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);
+
+            if (n == 0) {
+                break;
+            }
+
+            /* ERR_error_string_n() requires at least one byte */
+
+            if (p >= last - 1) {
+                goto next;
+            }
+
+            *p++ = ' ';
+
+            ERR_error_string_n(n, (char *) p, last - p);
+
+            while (p < last && *p) {
+                p++;
+            }
+
+            if (p < last && *data && (flags & ERR_TXT_STRING)) {
+                *p++ = ':';
+                p = ngx_cpystrn(p, (u_char *) data, last - p);
+            }
+
+        next:
+
+            (void) ERR_get_error();
         }
 
-        *p++ = ' ';
-
-        ERR_error_string_n(n, (char *) p, last - p);
-
-        while (p < last && *p) {
-            p++;
+        if (p < last) {
+            *p++ = ')';
         }
-
-        if (p < last && *data && (flags & ERR_TXT_STRING)) {
-            *p++ = ':';
-            p = ngx_cpystrn(p, (u_char *) data, last - p);
-        }
-
-    next:
-
-        (void) ERR_get_error();
-    }
-
-    ngx_log_error(level, log, err, "%*s)", p - errstr, errstr);
+    }
+
+    ngx_log_error(level, log, err, "%*s", p - errstr, errstr);
 }
 
 


More information about the nginx-devel mailing list