Mercurial > hg > nginx-quic
comparison src/event/ngx_event_openssl.c @ 7459:982008fbc4ba
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 25 Feb 2019 16:41:15 +0300 |
parents | 992bf7540a98 |
children | 77436d9951a1 |
comparison
equal
deleted
inserted
replaced
7458:0f0c75caa038 | 7459:982008fbc4ba |
---|---|
2741 | 2741 |
2742 va_start(args, fmt); | 2742 va_start(args, fmt); |
2743 p = ngx_vslprintf(errstr, last - 1, fmt, args); | 2743 p = ngx_vslprintf(errstr, last - 1, fmt, args); |
2744 va_end(args); | 2744 va_end(args); |
2745 | 2745 |
2746 p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p); | 2746 if (ERR_peek_error()) { |
2747 | 2747 p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p); |
2748 for ( ;; ) { | 2748 |
2749 | 2749 for ( ;; ) { |
2750 n = ERR_peek_error_line_data(NULL, NULL, &data, &flags); | 2750 |
2751 | 2751 n = ERR_peek_error_line_data(NULL, NULL, &data, &flags); |
2752 if (n == 0) { | 2752 |
2753 break; | 2753 if (n == 0) { |
2754 } | 2754 break; |
2755 | 2755 } |
2756 /* ERR_error_string_n() requires at least one byte */ | 2756 |
2757 | 2757 /* ERR_error_string_n() requires at least one byte */ |
2758 if (p >= last - 1) { | 2758 |
2759 goto next; | 2759 if (p >= last - 1) { |
2760 } | 2760 goto next; |
2761 | 2761 } |
2762 *p++ = ' '; | 2762 |
2763 | 2763 *p++ = ' '; |
2764 ERR_error_string_n(n, (char *) p, last - p); | 2764 |
2765 | 2765 ERR_error_string_n(n, (char *) p, last - p); |
2766 while (p < last && *p) { | 2766 |
2767 p++; | 2767 while (p < last && *p) { |
2768 } | 2768 p++; |
2769 | 2769 } |
2770 if (p < last && *data && (flags & ERR_TXT_STRING)) { | 2770 |
2771 *p++ = ':'; | 2771 if (p < last && *data && (flags & ERR_TXT_STRING)) { |
2772 p = ngx_cpystrn(p, (u_char *) data, last - p); | 2772 *p++ = ':'; |
2773 } | 2773 p = ngx_cpystrn(p, (u_char *) data, last - p); |
2774 | 2774 } |
2775 next: | 2775 |
2776 | 2776 next: |
2777 (void) ERR_get_error(); | 2777 |
2778 } | 2778 (void) ERR_get_error(); |
2779 | 2779 } |
2780 ngx_log_error(level, log, err, "%*s)", p - errstr, errstr); | 2780 |
2781 if (p < last) { | |
2782 *p++ = ')'; | |
2783 } | |
2784 } | |
2785 | |
2786 ngx_log_error(level, log, err, "%*s", p - errstr, errstr); | |
2781 } | 2787 } |
2782 | 2788 |
2783 | 2789 |
2784 ngx_int_t | 2790 ngx_int_t |
2785 ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx, | 2791 ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx, |