Skip to content

rustls: fix memory leak on repeated SSLKEYLOGFILE fails#21427

Closed
bagder wants to merge 2 commits into
masterfrom
bagder/rustls-keylog
Closed

rustls: fix memory leak on repeated SSLKEYLOGFILE fails#21427
bagder wants to merge 2 commits into
masterfrom
bagder/rustls-keylog

Conversation

@bagder
Copy link
Copy Markdown
Member

@bagder bagder commented Apr 23, 2026

Before this fix, Curl_tls_keylog_open() assigned the environment variable result to a global keylog_file_name without freeing any prior allocation. If the file cannot be opened (e.g., permission error) keylog_file_fp stays NULL, so subsequent calls to Curl_tls_keylog_open will overwrite keylog_file_name and leak the previous allocation.

Spotted by Codex Security

Before this fix, Curl_tls_keylog_open() assigned the environment
variable result to a global keylog_file_name without freeing any prior
allocation. If the file cannot be opened (e.g., permission error)
keylog_file_fp stays NULL, so subsequent calls to Curl_tls_keylog_open
will overwrite keylog_file_name and leak the previous allocation.

Spotted by Codex Security
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a resource-management issue in TLS key logging where repeated attempts to open SSLKEYLOGFILE could leak the previously allocated filename string when opening fails.

Changes:

  • Free keylog_file_name when curlx_fopen() fails in Curl_tls_keylog_open() to prevent leaks across repeated open attempts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/vtls/keylog.c Outdated
@bagder bagder marked this pull request as ready for review April 23, 2026 20:30
@bagder bagder closed this in 961a13e Apr 23, 2026
@bagder bagder deleted the bagder/rustls-keylog branch April 23, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants