Skip to content

Stop two ignored return values hiding failures - #1397

Open
ejohnstown wants to merge 3 commits into
wolfSSL:masterfrom
ejohnstown:sf33
Open

ejohnstown wants to merge 3 commits into
wolfSSL:masterfrom
ejohnstown:sf33

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

Both ignored returns hid real failures: one let a positive highwater
callback result read as a byte count, the other spun the example client
forever when the transport died mid-rekey.

  • Clamp positive highwater callback results to WS_SUCCESS, and check
    buffer_set_size() in SendReadPacket so an over-count cannot overrun
    the caller's buffer (CID 662152)
  • Example client readPeer ends the session on a failed rekey worker
    (CID 662153)

@ejohnstown ejohnstown changed the title Fix two Coverity CHECKED_RETURN findings Stop two ignored return values hiding failures Nov 19, 2026

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot 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.

Fenrir Automated Review — PR #1397

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 4 of 4 in-scope changed file(s) opened by the reviewer

Fenrir result: Approved ✅

No new issues found in the changed files.

Advisory only — this automated result does not count as a GitHub approval.

Review tier: Max

@ejohnstown

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot 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.

I reviewed this PR and didn't find any bugs. The fixes are small, but they touch the transport's rekey-trigger path and SFTP read buffering, and an earlier automated review on this PR has had no follow-up commit, so a human look would still be worthwhile.

What was reviewed:

  • HighwaterCheck: a positive callback result is now changed to WS_SUCCESS and negative results still pass through, which matches the new test_ByteHighwater cases.
  • SendReadPacket remainder loop: if ret is larger than the remaining size, the unsigned subtraction wraps to a value bigger than buffer->sz. wolfSSH_SFTP_buffer_set_size rejects that, so the loop now exits to cleanup before recvSz or the output offset is advanced.
  • client.c readPeer: a fatal worker result during rekey now leaves ret negative, which ends the outer while (ret >= 0) loop. Non-fatal codes are still mapped to 0.
Extended reasoning...

The change touches src/internal.c (the highwater callback that triggers rekeying), src/wolfsftp.c (SFTP read buffer bounds), the example client, and a unit test. Together that is about 40 lines. It touches security-sensitive surface: SSH key-lifetime limits and how SFTP received data is bounded into the caller's buffer. No bugs were found, and no CODEOWNERS file covers these paths. I deferred instead of approving because this is security-critical library code and the timeline has a third-party review whose content I can't see, with no later commit addressing it.

HighwaterCheck() hands the application callback's result back through
wolfSSH_SendPacket() into wolfSSH_stream_read(), which returns it as a
byte count. A positive result now comes back as WS_SUCCESS.

- sftp: check buffer_set_size() in SendReadPacket's remainder loop, so
  a count over the request ends the read instead of overrunning out
- tests: cover positive and negative callback results in ByteHighwater

Issue: CID-662152
wolfSSH_stream_read() keeps answering WS_REKEYING while a key exchange
runs, so a transport that dies mid-rekey is reported only by the
wolfSSH_worker() call that drives it. readPeer() now ends the session
on any worker result that is not a session status, instead of spinning.

Issue: CID-662153
The receive loop looks for the newline in scpRecvMsgSz bytes and sets
sz from the newline offset after the loop, so copying scpRecvMsgSz
into sz after each read is never used.

Issue: CID-662317
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.

3 participants