Skip to content

Tighten integer widths and checked returns - #1398

Merged
philljj merged 3 commits into
wolfSSL:masterfrom
ejohnstown:sf34
Nov 20, 2026
Merged

philljj merged 3 commits into
wolfSSL:masterfrom
ejohnstown:sf34

Conversation

@ejohnstown

@ejohnstown ejohnstown commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

None of these were bugs: each bound or error case was already handled,
but out of the analyzer's sight. Each change moves the check to the point
of use, with no behavior change for valid input.

  • buffer_read() takes its size as a word32 and rejects one over
    0x7FFFFFFF, and DoName() checks its read offset against the size
    (CIDs 661741, 661744, 661745, 661747-661751)
  • GetConfigInt() does its arithmetic in int, the width of its limit
    (CID 661742)
  • The wolfssh client skips setting and restoring terminal modes when
    tcgetattr() or the raw-mode tcsetattr() fails (CIDs 661743, 661746)

wolfSSH_SFTP_buffer_read() now takes its size as a word32, the type of
the buffer size its callers pass, and rejects a size over 0x7FFFFFFF
before it is returned as an int. wolfSSH_SFTP_DoName() also rejects a
read offset past the size, so its size minus idx cannot wrap.

Issue: CID-661741, CID-661744, CID-661745, CID-661747,
       CID-661748, CID-661749, CID-661750, CID-661751
GetConfigInt() checks each step against 0x7FFFFFFF, so the value, the
time multiplier and the running total are now int, the same width as
the limit. The return type stays long for the callers.

Issue: CID-661742
modes_store() records whether tcgetattr() read the stdin modes.
modes_clear() and modes_reset() do nothing when it did not, and a
failed raw-mode tcsetattr() leaves nothing for modes_reset() to restore.

Issue: CID-661743, CID-661746

@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 #1398

Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 3 of 3 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. It changes the size handling in the SFTP receive buffer, which parses data from the peer, so a human look would still be worthwhile.

What was reviewed:

  • GetConfigInt: with int arithmetic, the checks against CONFIG_INT_MAX still run before each multiply and add, so signed overflow can't happen. The largest multiplier (604800) fits in an int.
  • wolfSSH_SFTP_buffer_read: I checked every caller. Values passed as int, such as state->maxSz, now convert to word32, so a negative value hits the new 0x7FFFFFFF check and returns WS_BUFFER_E. Before, it went on to the allocation. All callers treat a negative return as an error.
  • The new DoName check stops size - idx from wrapping, and the termSaved flag keeps modes_reset from restoring terminal modes that were never saved.
Extended reasoning...

The change touches three files: the wolfssh client's terminal-mode save and restore, wolfsshd's GetConfigInt, and the SFTP receive buffer read plus its callers in src/wolfsftp.c. The SFTP buffer read handles length fields from the peer, which is security-sensitive input parsing. The diff is small and appears correct. An earlier automated review left a comment and the author replied, but this run can't see what either said. Because the change touches network-input parsing in a security library, deferring is safer than approving.

@philljj
philljj merged commit edd02bf into wolfSSL:master Nov 20, 2026
223 checks passed
@ejohnstown
ejohnstown deleted the sf34 branch November 20, 2026 17:11
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