Skip to content

Comments

Static analysis fixes#880

Merged
dgarske merged 7 commits intowolfSSL:masterfrom
LinuxJedi:static-fixes
Feb 23, 2026
Merged

Static analysis fixes#880
dgarske merged 7 commits intowolfSSL:masterfrom
LinuxJedi:static-fixes

Conversation

@LinuxJedi
Copy link
Member

Fix some bugs found by the wolfSSL static analyzer:

  • Fix logical operator in public key type validation checks
  • Fix buffer over-read in wolfSSH_DoModes terminal mode parsing
  • Fix two bugs in PostRemoveId agent identity removal
  • Fix digest comparison in FindKeyId to use id->id field
  • Fix octal validation loop index in GetScpFileMode
  • Fix wrong variable checked in DoCheckUser auth callback
  • Fix NULL pointer dereference in wolfSSH_SetTpmDev/SetTpmKey

Change && to || in 5 instances where public key type matching used
AND instead of OR, causing WMEMCMP to be skipped when type sizes
matched. Two key types with the same size but different content
would incorrectly pass validation.

Affected functions: DoUserAuthRequestRsaCert, DoUserAuthRequestEcc,
and DoUserAuthRequestEccCert.
The while loop condition only checked that the opcode byte was in bounds
(idx < modesSz) but not the 4-byte argument read by ato32(). When
modesSz had a remainder of 1 mod 5 and the trailing byte was a valid
opcode (1-159) rather than TTY_OP_END, ato32() would read 4 bytes past
the buffer. Change the loop guard to require a full TERMINAL_MODE_SZ
bytes remaining before entering the loop body.
Fix inverted WMEMCMP check that removed non-matching entries and kept
matching ones. WMEMCMP returns 0 on match, so the condition was backwards.

Fix head-of-list removal setting idList to NULL instead of cur->next,
which dropped all remaining entries after the removed one
WMEMCMP was comparing the computed SHA-256 digest against the
WOLFSSH_AGENT_ID struct pointer instead of the id field within
the struct, causing key lookups by digest to never match.
The upper-bound check in the octal-to-integer conversion loop used
modeOctet[0] instead of modeOctet[i], so only the first character
was validated against '7'. Characters at positions 1-3 could have
values above '7' without triggering an error.
In DoCheckUser, after calling auth->checkUserCb(usr) into rc, the
failure check on line 1063 compared ret instead of rc against
WSSHD_AUTH_FAILURE. Since ret is WOLFSSH_USERAUTH_SUCCESS at that
point, the condition was always false, causing callback failures to
fall through to the generic error branch with WOLFSSH_USERAUTH_FAILURE
instead of returning WOLFSSH_USERAUTH_INVALID_USER.
Move the NULL validation checks inside the existing NULL guards for
ssh and ssh->ctx. Previously, the check accessed ssh->ctx outside
the guard, causing a NULL dereference when ssh or ssh->ctx was NULL.
Also fix wolfSSH_SetTpmKey to check tpmKey instead of tpmDev.
@dgarske dgarske merged commit 0a0341f into wolfSSL:master Feb 23, 2026
124 of 126 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.

3 participants