Repository navigation
Tighten integer widths and checked returns - #1398
Conversation
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
left a comment
There was a problem hiding this comment.
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
|
@claude review |
There was a problem hiding this comment.
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 - idxfrom 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.
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.
0x7FFFFFFF, and DoName() checks its read offset against the size
(CIDs 661741, 661744, 661745, 661747-661751)
(CID 661742)
tcgetattr() or the raw-mode tcsetattr() fails (CIDs 661743, 661746)