Skip to content

Static analysis fixes#976

Merged
padelsbach merged 4 commits into
wolfSSL:masterfrom
ejohnstown:static-fixes-3
May 13, 2026
Merged

Static analysis fixes#976
padelsbach merged 4 commits into
wolfSSL:masterfrom
ejohnstown:static-fixes-3

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

  • Pin expectMsgId to MSGID_KEXDH_GEX_INIT after KEXDH_GEX_GROUP; null-check ssh->handshake (F-3668).
  • Reject ParseRFC6187 name lengths that would overflow when added to sizeof(word32), preventing OOB reads (F-1277).
  • ForceZero the lastBlock stack buffers on both remainder paths in GenerateKey (F-2494).
  • ForceZero newKey before free in DoPemKey/DoOpenSshKey and the PEM read buffer in wolfSSH_ReadKey_file (F-2885, F-3211, F-3212).

Copilot AI review requested due to automatic review settings May 12, 2026 18:08
Copy link
Copy Markdown
Contributor

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

Note

Copilot was unable to run its full agentic suite in this review.

Addresses multiple static-analysis findings by tightening bounds checks, hardening handshake state transitions, and zeroing sensitive buffers before free/return.

Changes:

  • Harden key parsing/reading paths by tracking buffer sizes and ForceZero’ing sensitive allocations before freeing.
  • Add ForceZero on stack lastBlock buffers in both remainder paths of GenerateKey.
  • Add RFC6187 name-length overflow protection and tighten KEXDH_GEX message expectation handling (incl. ssh->handshake null-check).

Reviewed changes

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

File Description
src/ssh.c Securely clear key/file buffers and adjust allocation sizing for PEM/OpenSSH key parsing.
src/internal.c Zero sensitive stack buffers in key derivation; harden KEXDH_GEX group send flow and expected message tracking.
apps/wolfssh/common.c Add bounds check to prevent RFC6187 name-length overflow/OOB reads.

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

Comment thread apps/wolfssh/common.c
Comment thread src/internal.c
Comment thread src/ssh.c
Comment thread src/ssh.c Outdated
Comment thread src/ssh.c
padelsbach
padelsbach previously approved these changes May 12, 2026
- ForceZero newKey before WFREE in DoPemKey/DoOpenSshKey,
  covering both locally-allocated and caller-supplied buffers.
- ForceZero PEM file buffer after read in wolfSSH_ReadKey_file
- Track newKeySz for caller-supplied buffer path

Issue: F-2885, F-3211, F-3212
- Add ForceZero on lastBlock in both remainder paths
- Prevents leftover key-derivation material on the stack

Issue: F-2494
- Reject name lengths that would overflow m when added
  to sizeof(word32), preventing OOB reads on later checks.

Issue: F-1277
- Set expectMsgId to MSGID_KEXDH_GEX_INIT so the server rejects
  any other KEX message at this stage (RFC 4419 sec 3).
- Reject NULL ssh->handshake in the entry check now that the
  success path dereferences it.

Issue: F-3668
@padelsbach padelsbach merged commit bd75cb4 into wolfSSL:master May 13, 2026
133 of 134 checks passed
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.

4 participants