Skip to content

CONC-818 report CR_SERVER_LOST on TLS connection close#308

Draft
FaramosCZ wants to merge 1 commit intomariadb-corporation:3.4from
FaramosCZ:CONC-818
Draft

CONC-818 report CR_SERVER_LOST on TLS connection close#308
FaramosCZ wants to merge 1 commit intomariadb-corporation:3.4from
FaramosCZ:CONC-818

Conversation

@FaramosCZ
Copy link
Copy Markdown
Contributor

@FaramosCZ FaramosCZ commented Apr 14, 2026

When the server closes a connection, ma_tls_read() in the OpenSSL and GnuTLS plugins unconditionally calls
ma_tls_set_error(), which sets CR_SSL_CONNECTION_ERROR. The caller ma_net_safe_read() then preserves that error code instead of reporting the correct CR_SERVER_LOST.

The Schannel plugin already handles this correctly: it returns 0 on SEC_I_CONTEXT_EXPIRED without setting any TLS error (schannel.c:640-642).

Apply the same logic to OpenSSL and GnuTLS. Detect connection close and return 0 without setting error:

OpenSSL:

  • SSL_ERROR_ZERO_RETURN: orderly close (close_notify)
  • SSL_ERROR_SYSCALL with empty error queue: EOF without close_notify (OpenSSL 1.x)
  • SSL_ERROR_SSL with SSL_R_UNEXPECTED_EOF_WHILE_READING: same EOF, reported differently by OpenSSL 3.x

GnuTLS:

  • rc == 0: orderly close (close_notify)
  • GNUTLS_E_PREMATURE_TERMINATION: EOF without close_notify (GnuTLS 3.7.4+)

Related to MariaDB/server#4929

When the server closes a connection, ma_tls_read() in the
OpenSSL and GnuTLS plugins unconditionally calls
ma_tls_set_error(), which sets CR_SSL_CONNECTION_ERROR.
The caller ma_net_safe_read() then preserves that error
code instead of reporting the correct CR_SERVER_LOST.

The Schannel plugin already handles this correctly:
it returns 0 on SEC_I_CONTEXT_EXPIRED without setting
any TLS error (schannel.c:640-642).

Apply the same logic to OpenSSL and GnuTLS.  Detect
connection close and return 0 without setting error:

OpenSSL:
- SSL_ERROR_ZERO_RETURN: orderly close (close_notify)
- SSL_ERROR_SYSCALL with empty error queue: EOF without
  close_notify (OpenSSL 1.x)
- SSL_ERROR_SSL with SSL_R_UNEXPECTED_EOF_WHILE_READING:
  same EOF, reported differently by OpenSSL 3.x

GnuTLS:
- rc == 0: orderly close (close_notify)
- GNUTLS_E_PREMATURE_TERMINATION: EOF without
  close_notify (GnuTLS 3.7.4+)

Co-Authored-By: Claude AI <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant