Skip to content

pem: fix ssh2_pem_parse_blob() memleak in no-MD5 builds - #2390

Closed
vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:pem-no-md5-memleak
Closed

vszakats wants to merge 1 commit into
libssh2:masterfrom
vszakats:pem-no-md5-memleak

Conversation

@vszakats

@vszakats vszakats commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

When processing encrypted PEM files.

Also: make sure to initialize returned pointer/length on fail.

Reported by Copilot
Bug: #2388 (comment)

When processing encrypted PEM files.

Reported by Copilot
Bug: libssh2#2388 (comment)
Copilot AI review requested due to automatic review settings July 22, 2026 08:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a memory leak in ssh2_pem_parse_blob() when processing encrypted PEM input in builds where LIBSSH2_MD5_PEM is disabled (no-MD5 builds). It does this by initializing output parameters up front and centralizing cleanup of decoded key material on all error paths.

Changes:

  • Initialize *data/*datalen at function entry to avoid stale outputs and make cleanup safe.
  • Remove repeated zero/free logic in multiple error branches and replace with a single out: cleanup block.
  • Ensure decoded key material is securely zeroed and freed on failure, including the no-MD5 (#else) path.

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

@vszakats vszakats closed this in 3b84c15 Jul 22, 2026
@vszakats
vszakats deleted the pem-no-md5-memleak branch July 22, 2026 08:40
@vszakats vszakats mentioned this pull request Jul 22, 2026
1 task done
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.

2 participants