Skip to content

src: propagate session to replace bare allocators with SSH2 ones - #2544

Closed
vszakats wants to merge 23 commits into
libssh2:masterfrom
vszakats:nomalloc1
Closed

vszakats wants to merge 23 commits into
libssh2:masterfrom
vszakats:nomalloc1

Conversation

@vszakats

@vszakats vszakats commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Also:

  • GHA: build test WinCNG with legacy options enabled with both mingw-w64
    and MSVC.
  • add ssh2_zero_free() to clear memory and free using SSH2_FREE().
  • openssl, wincng: use ssh2_zero_free().
  • replace bare allocators with SSH2 ones in places where session was
    already available.

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

Propagates session-aware allocation through cryptographic verification and DSA signing paths.

Changes:

  • Adds session parameters to internal crypto APIs and callers.
  • Replaces selected bare allocations with session allocators.
  • Updates backend implementations and crypto documentation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/wincng.c Converts Windows CNG temporary allocations.
src/os400qc3.c Updates RSA verification signatures.
src/openssl.c Uses session allocation for RSA hashes.
src/mbedtls.c Uses session allocation for RSA hashes.
src/libgcrypt.c Updates RSA and DSA interfaces.
src/hostkey.c Passes sessions into crypto operations.
src/HACKING-CRYPTO.md Documents revised crypto signatures.
src/crypto.h Declares revised internal APIs.

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

Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/wincng.c Resolved
Comment thread src/mbedtls.c Resolved
Comment thread src/openssl.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 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/wincng.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 10 out of 10 changed files in this pull request and generated no new comments.

Suppressed comments (1)

src/wincng.c:2582

  • SSH2_FEEE is not defined, so WinCNG builds with ECDSA enabled fail to compile in this cleanup path. Use the session-aware SSH2_FREE macro used for the matching allocation.
        SSH2_FEEE(session, cng_signature);

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 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread src/openssl.c Outdated

if(secret)
free(secret);
SSH2_FREE(session, secret);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Right, pre-existing/unrelated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

→ PR #2545

vszakats added a commit that referenced this pull request Aug 27, 2026
…penSSL 1.1.1

Also:
- use separate variable to store the secret buffer size and the length
  of the actual secret.
- fix the type of the actual secret size to be `int` to match the API
  and avoid a cast.

Reported by Copilot
Bug: #2544 (comment)
Follow-up to aba34f5 #41

Closes #2545

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 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread src/openssl.c

if(temp_buffer)
free(temp_buffer);
SSH2_FREE(session, temp_buffer);

@vszakats vszakats Aug 27, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Another pre-existing mismatch. Fixing in a next PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

→ PR #2547

@vszakats vszakats closed this in a2ac6bd Aug 27, 2026
@vszakats
vszakats deleted the nomalloc1 branch August 27, 2026 17:53
vszakats added a commit that referenced this pull request Aug 27, 2026
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

Closes #2546
vszakats added a commit that referenced this pull request Aug 27, 2026
… with OpenSSL 3+

Reported by Copilot
Bug: #2544 (comment)
Follow-up to b0ab005 #1207

Closes #2547
vszakats added a commit that referenced this pull request Aug 27, 2026
…use SSH2 allocators

Replacing `OPENSSL_malloc()`/`OPENSSL_zalloc()`.

Follow-up to a2ac6bd #2544

Closes #2549
vszakats added a commit that referenced this pull request Aug 27, 2026
vszakats added a commit that referenced this pull request Aug 29, 2026
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