Skip to content

Commit 4488a84

Browse files
tls: enhance error message handling to prevent corrupted OpenSSL errors
Addresses CodeRabbit suggestion from GitHub PR #10850 discussion_r2329667784. The original fix correctly handled SSL_ERROR_SYSCALL but still had an issue where SSL_get_error() classification codes (like SSL_ERROR_SYSCALL=5) were being incorrectly passed to ERR_error_string_n(), which expects actual OpenSSL error queue codes. This caused corrupted error messages like "error:00000005:lib(0):func(0):DH lib". This enhancement: - Uses ERR_peek_last_error() to get actual OpenSSL error codes from the queue - Only calls ERR_error_string_n() with valid OpenSSL error codes - Falls back to logging the SSL error classification number when no queue error exists - Provides cleaner, more informative TLS error messages Combined with the original SSL_ERROR_SYSCALL errno=0 fix, this resolves both the race condition crashes and the error message corruption issues. References: #10850 (comment) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 26e2c98 commit 4488a84

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/tls/openssl.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,8 +1192,16 @@ static int tls_net_handshake(struct flb_tls *tls,
11921192
}
11931193
}
11941194
else {
1195-
ERR_error_string_n(ret, err_buf, sizeof(err_buf)-1);
1196-
flb_error("[tls] error: %s", err_buf);
1195+
/* Get the actual OpenSSL error from queue instead of SSL_get_error() classification */
1196+
unsigned long err_code = ERR_peek_last_error();
1197+
if (err_code != 0) {
1198+
ERR_error_string_n(err_code, err_buf, sizeof(err_buf)-1);
1199+
flb_error("[tls] error: %s", err_buf);
1200+
}
1201+
else {
1202+
/* No OpenSSL error in queue, log the SSL error classification */
1203+
flb_error("[tls] unknown SSL error (class: %d)", ret);
1204+
}
11971205
}
11981206

11991207
pthread_mutex_unlock(&ctx->mutex);

0 commit comments

Comments
 (0)