Skip to content

Commit

Permalink
SSL: removed logging of empty "(SSL:)" in ngx_ssl_error().
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdounin committed Feb 25, 2019
1 parent dce5823 commit 2d7faa2
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/event/ngx_event_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2743,41 +2743,47 @@ ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...)
p = ngx_vslprintf(errstr, last - 1, fmt, args);
va_end(args);

p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
if (ERR_peek_error()) {
p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);

for ( ;; ) {
for ( ;; ) {

n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);
n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);

if (n == 0) {
break;
}
if (n == 0) {
break;
}

/* ERR_error_string_n() requires at least one byte */
/* ERR_error_string_n() requires at least one byte */

if (p >= last - 1) {
goto next;
}
if (p >= last - 1) {
goto next;
}

*p++ = ' ';
*p++ = ' ';

ERR_error_string_n(n, (char *) p, last - p);
ERR_error_string_n(n, (char *) p, last - p);

while (p < last && *p) {
p++;
}
while (p < last && *p) {
p++;
}

if (p < last && *data && (flags & ERR_TXT_STRING)) {
*p++ = ':';
p = ngx_cpystrn(p, (u_char *) data, last - p);
}
if (p < last && *data && (flags & ERR_TXT_STRING)) {
*p++ = ':';
p = ngx_cpystrn(p, (u_char *) data, last - p);
}

next:
next:

(void) ERR_get_error();
(void) ERR_get_error();
}

if (p < last) {
*p++ = ')';
}
}

ngx_log_error(level, log, err, "%*s)", p - errstr, errstr);
ngx_log_error(level, log, err, "%*s", p - errstr, errstr);
}


Expand Down

0 comments on commit 2d7faa2

Please sign in to comment.