Skip to content

Static Analysis Fixes#983

Open
ejohnstown wants to merge 8 commits into
wolfSSL:masterfrom
ejohnstown:sf5
Open

Static Analysis Fixes#983
ejohnstown wants to merge 8 commits into
wolfSSL:masterfrom
ejohnstown:sf5

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

Small hardening pass across protocol parsing, cert verification, and client cleanup.

  • DoProtoId: enforce case-sensitive SSH- prefix match per RFC 4253 4.2 (F-2865)
  • DoNewKeys: reject SSH_MSG_NEWKEYS with non-empty payload (F-2079)
  • DoKexInit: stop over-advancing past the KEXINIT reserved field; it's a fixed uint32 0 per RFC 4253 7.1, not a length prefix (F-869)
  • DoKexInit: set ret on host-key algo mismatch instead of bare return (F-3204)
  • CERTMAN_VerifyCerts_buffer: reject zero certsCount explicitly (F-409)
  • wolfSSH_DoControlSeq: bounds-check escBuf before read (F-250)
  • ClientFreeBuffers: zero private key and password buffers on free (F-249)
  • ClientPublicKeyCheck: drop dead if (otherMatch) wrapper (F-3205)

- Replace mid-function return so end-of-function cleanup runs.

Issue: F-3204
- otherMatch is set to 1 immediately above; guard always true.

Issue: F-3205
Copilot AI review requested due to automatic review settings May 15, 2026 17:43
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

Hardening-focused PR addressing several static-analysis findings across core protocol parsing/negotiation, certificate-chain verification, terminal escape parsing, and client-side sensitive-buffer cleanup.

Changes:

  • Tighten protocol message parsing to better match RFC requirements (e.g., NEWKEYS payload rejection, KEXINIT reserved-field handling, case-sensitive version comparison).
  • Harden certificate verification input validation (explicitly reject certsCount == 0).
  • Improve client safety by securely zeroing sensitive buffers during cleanup.

Reviewed changes

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

File Description
src/wolfterm.c Adds an additional bounds check during CSI escape-sequence parsing.
src/internal.c Tightens SSH identification matching and hardens KEXINIT/NEWKEYS parsing behavior.
src/certman.c Rejects zero-certificate chains up front in buffer verification.
apps/wolfssh/common.c Removes redundant conditional output and zeroes sensitive client buffers on free.

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

Comment thread src/wolfterm.c Outdated
Comment thread src/internal.c
@ejohnstown ejohnstown force-pushed the sf5 branch 2 times, most recently from fd6dd00 to c0048ed Compare May 15, 2026 18:09
- Per RFC 4253 7.1 the reserved field is uint32 0, not a length
  prefix; reject non-zero values with WS_PARSE_E.
- Add regression test.

Issue: F-869
- Zero private key and password buffers in both apps/wolfssh
  and examples client.
- Also zero keyboard-interactive response buffers in the
  example client.

Issue: F-249
- Guard escBuf[i] read when getArgs consumes all input without a command.
- Cap WMEMCPY against WOLFSSL_MAX_ESCBUF; escBufSz can exceed 16.
- Update escBufSz on WS_WANT_READ resume so CSI leftovers survive
  multi-fill reads.

Issue: F-250
- Without the guard, inner loops short-circuit and WS_SUCCESS
  is returned without any verification.
- Add test case covering the new and existing bad-arg paths.

Issue: F-409
- Reject SSH_MSG_NEWKEYS when len != 0 per RFC 4253 7.3.
- Update wolfSSH_TestDoNewKeys to take buf/len/idx instead
  of assuming NULL/0, and add a non-zero len test case.

Issue: F-2079
- Per RFC 4253 4.2 use WSTRNCMP instead of WSTRNCASECMP for
  prefix and full-ID comparisons.
- Update client tests; add server test vectors expecting
  rejection of lowercase/mixed case.

Issue: F-2865
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