Skip to content

fix: free OpenSSL state after failed outbound TLS setup - #295

Draft
rgerhards wants to merge 2 commits into
rsyslog:masterfrom
rgerhards:agent/fix-openssl-connect-error-cleanup
Draft

fix: free OpenSSL state after failed outbound TLS setup#295
rgerhards wants to merge 2 commits into
rsyslog:masterfrom
rgerhards:agent/fix-openssl-connect-error-cleanup

Conversation

@rgerhards

@rgerhards rgerhards commented Aug 4, 2026

Copy link
Copy Markdown
Member

What

  • mark the socket BIO as SSL-owned immediately after SSL_set_bio()
  • free the SSL object and clear the stored pointer whenever outbound TLS initialization fails
  • retain fallback cleanup for a BIO that has not yet transferred ownership
  • add an OpenSSL authentication-failure Valgrind regression

Why

The failed outbound handshake path freed the local BIO pointer but retained the SSL object. After SSL_set_bio(), however, the SSL object owns that BIO. This both leaked the SSL allocation graph and left cleanup ownership inconsistent.

Impact

Failed outbound TLS setup now releases its OpenSSL state and leaves pThis->ssl null. Successful connections and the public ABI are unchanged.

Checks

  • OpenSSL-only debug build
  • make -j60 check: 30 passed, 1 skipped
  • targeted failed-handshake Valgrind regression: passed

Summary by cubic

Fixes memory leak and BIO ownership after failed outbound TLS setup with OpenSSL. Failed handshakes now release all OpenSSL state and leave pThis->ssl null; successful connections are unchanged.

  • Bug Fixes
    • Mark the socket BIO as SSL-owned right after SSL_set_bio().
    • On handshake failure, free the SSL object and clear pThis->ssl; keep fallback BIO free if ownership wasn’t transferred.
    • Add a Valgrind regression for the auth-failure path, run it via the project libtool, and include it in TLS Valgrind tests.

Written for commit bb19790. Summary will update on new commits.

Review in cubic

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