Skip to content

kex, pem: use ssh2_zero_free() where applicable - #2546

Closed
vszakats wants to merge 7 commits into
libssh2:masterfrom
vszakats:use-more-zero-free
Closed

vszakats wants to merge 7 commits into
libssh2:masterfrom
vszakats:use-more-zero-free

Conversation

@vszakats

@vszakats vszakats commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Merge ssh2_explicit_zero() / SSH2_[SAFE]FREE() pairs into
ssh2_zero_free() calls, to simplify a common pattern, also allowing to
drop the NULL check at each call-site.

Follow-up to a2ac6bd #2544

@vszakats
vszakats requested a balanced review from Copilot August 27, 2026 17:57
@vszakats vszakats changed the title pem, kex: use ssh2_zero_free() where applicable kex, pem: use ssh2_zero_free() where applicable Aug 27, 2026

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

Replaces sensitive-memory cleanup sequences with the centralized ssh2_zero_free() helper.

Changes:

  • Simplifies PEM buffer cleanup.
  • Simplifies key-exchange secret and key cleanup.
  • Explicitly nulls persistent cleanup-state pointers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pem.c Centralizes secure PEM buffer cleanup.
src/kex.c Centralizes secure KEX key cleanup.
Suppressed comments (1)

src/kex.c:328

  • This also needs to preserve the free_key ownership check. For normal standalone HMAC methods, initialization stores key in remote.mac_abstract and returns free_key = 0; unconditionally zeroing and freeing it makes incoming packet authentication use freed memory and later causes a second free in mac_method_common_dtor().
        ssh2_zero_free(session, key, session->remote.mac->key_len);

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/kex.c Resolved

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@vszakats vszakats closed this in 1e7ba97 Aug 27, 2026
@vszakats
vszakats deleted the use-more-zero-free branch August 27, 2026 18:33
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