Klaus Demo nginx / 2d7faa2
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. Maxim Dounin 1 year, 9 months ago
1 changed file(s) with 41 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
27422742 p = ngx_vslprintf(errstr, last - 1, fmt, args);
27432743 va_end(args);
27442744
2745 p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
2746
2747 for ( ;; ) {
2748
2749 n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);
2750
2751 if (n == 0) {
2752 break;
2753 }
2754
2755 /* ERR_error_string_n() requires at least one byte */
2756
2757 if (p >= last - 1) {
2758 goto next;
2759 }
2760
2761 *p++ = ' ';
2762
2763 ERR_error_string_n(n, (char *) p, last - p);
2764
2765 while (p < last && *p) {
2766 p++;
2767 }
2768
2769 if (p < last && *data && (flags & ERR_TXT_STRING)) {
2770 *p++ = ':';
2771 p = ngx_cpystrn(p, (u_char *) data, last - p);
2772 }
2773
2774 next:
2775
2776 (void) ERR_get_error();
2777 }
2778
2779 ngx_log_error(level, log, err, "%*s)", p - errstr, errstr);
2745 if (ERR_peek_error()) {
2746 p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
2747
2748 for ( ;; ) {
2749
2750 n = ERR_peek_error_line_data(NULL, NULL, &data, &flags);
2751
2752 if (n == 0) {
2753 break;
2754 }
2755
2756 /* ERR_error_string_n() requires at least one byte */
2757
2758 if (p >= last - 1) {
2759 goto next;
2760 }
2761
2762 *p++ = ' ';
2763
2764 ERR_error_string_n(n, (char *) p, last - p);
2765
2766 while (p < last && *p) {
2767 p++;
2768 }
2769
2770 if (p < last && *data && (flags & ERR_TXT_STRING)) {
2771 *p++ = ':';
2772 p = ngx_cpystrn(p, (u_char *) data, last - p);
2773 }
2774
2775 next:
2776
2777 (void) ERR_get_error();
2778 }
2779
2780 if (p < last) {
2781 *p++ = ')';
2782 }
2783 }
2784
2785 ngx_log_error(level, log, err, "%*s", p - errstr, errstr);
27802786 }
27812787
27822788