Skip to content

Comments

Static analysis fixes#881

Open
ejohnstown wants to merge 5 commits intowolfSSL:masterfrom
ejohnstown:static-fixes
Open

Static analysis fixes#881
ejohnstown wants to merge 5 commits intowolfSSL:masterfrom
ejohnstown:static-fixes

Conversation

@ejohnstown
Copy link
Contributor

Fix some bugs found by the wolfSSL static analyzer:

  • Fix null check for duplicated string
  • Check bounds on addition with value from peer
  • Fix null dereference after failed channel lookup
  • Check correct pointer for null
  • Fix wrong bitwise operator for testing attribute

When making a copy of a string, check the destination pointer of the
copy rather than the original.

Affected function: CheckPasswordUnix.
Copilot AI review requested due to automatic review settings February 25, 2026 00:37
Copy link

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

This PR fixes five distinct bugs identified by static analysis in the wolfSSH library, addressing critical security and stability issues related to null pointer checks, integer overflow, and incorrect bitwise operations.

Changes:

  • Fixed null pointer dereference when channel lookup fails by properly structuring the error handling with braces and else-if
  • Corrected bitwise operator from OR to AND when testing FILE_ATTRIBUTE_READONLY flag on Windows
  • Added integer overflow protection for peer window size adjustment by checking bounds before addition
  • Fixed incorrect pointer null check after CTX allocation (checking dereferenced pointer instead of pointer itself)
  • Fixed incorrect variable null check after string duplication (checking source instead of destination)

Reviewed changes

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

File Description
src/wolfscp.c Fixed null dereference on channel EOF check and corrected bitwise operator for file attribute testing
src/internal.c Added overflow protection for peer window size adjustment with bounds checking
apps/wolfsshd/wolfsshd.c Fixed null check to validate dereferenced CTX pointer after allocation
apps/wolfsshd/auth.c Fixed null check to validate newly duplicated string instead of source string

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

Bounds check the bytes to add from the peer against the window size.

Affected function: DoChannelWindowAdjust.
When looking up the channel object for the current channel ID, if the
lookup failed, we still checked if the channel had an EOF with a null
pointer. That function, does check for NULL and error, but it is better
to error out sooner.

Affected function: ReceiveScpMessage.
After creating a new SSH context, the pointer returned wasn't checked;
the pointer to the pointer was checked. Changed to the correct pointer.

Affected function: SetupCTX.
Was using OR to check if a bit was set in the read-only file attribute.
This was always succeeding. Needed to change to an AND to see if it is
set.

Affected function: GetFileStats.
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.

1 participant