Skip to content

Misc Static Analysis Fixes#948

Merged
padelsbach merged 6 commits intowolfSSL:masterfrom
ejohnstown:misc-static
Apr 22, 2026
Merged

Misc Static Analysis Fixes#948
padelsbach merged 6 commits intowolfSSL:masterfrom
ejohnstown:misc-static

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

  • Fix potential double-free: Null out a pointer after freeing in wolfSSH_CTX_UseCert_buffer() test to prevent a double-free if the second cert load fails.
  • Fix scan-build errno warnings: Replace rewind() with fseek() in both the WREWIND macro and api.c test helper to avoid scan-build flagging the implicit errno clear, and remove a redundant errno check after execv().
  • Fix unchecked return value warning: Handle the return value of dup() in regress.c to silence the static analysis warning.
  • 7-bit clean ASCII: Scrub non-ASCII characters (curly quotes, n-dashes) from the main source files to ensure all text is 7-bit clean.

Static analysis indicated the potential to double-free a pointer in the
`wolfSSH_CTX_UseCert_buffer()` test. Loading the second cert after
freeing the first cert could fail and the test cleanup would free the
pointer again. Just set pointer to null after freeing.
Clean up the main set of files to be 7-bit clean ASCII. There were many
single and double-quotes and n-dashes.
Remove the errno check in the condition after execv(). If execv()
returns at all, it has failed, so checking ret alone is sufficient.
The errno check was flagged by clang scan-build as potentially
reading an undefined value (unix.Errno).
Copilot AI review requested due to automatic review settings April 21, 2026 22:19
Copy link
Copy Markdown
Contributor

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 addresses a set of static-analysis findings and consistency issues across the wolfSSH codebase, primarily around file handling, error checks, and ensuring 7-bit clean ASCII in source/test text.

Changes:

  • Replaces rewind() usage with fseek() in the portability layer and a test helper to avoid scan-build errno warnings.
  • Tightens test robustness by preventing potential double-free patterns and asserting dup() success.
  • Scrubs non-ASCII punctuation from source/comments/docs and removes a redundant errno check after execv().

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wolfssh/port.h Changes WREWIND implementation from rewind() to fseek(..., SEEK_SET)
tests/regress.c Adds an assertion for dup(STDIN_FILENO) return value
tests/auth.c Replaces non-ASCII dashes in comments with ASCII hyphens
tests/api.c Replaces rewind() with fseek() in load_file() and nulls freed cert pointer in a test
scripts/fwd.test.expect Replaces non-ASCII em-dash with ASCII hyphen in expected output
examples/sftpclient/sftpclient.c Replaces non-ASCII punctuation in comments
apps/wolfsshd/wolfsshd.c Removes redundant && errno check after execv()
apps/wolfsshd/test/test_configuration.c Replaces non-ASCII punctuation in comments
ChangeLog.md Replaces curly quotes / non-ASCII punctuation with ASCII equivalents

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

Comment thread wolfssh/port.h Outdated
Comment thread tests/api.c
Replace rewind() with fseek(s, 0, SEEK_SET) in the WREWIND macro.
rewind() internally clears errno, which scan-build flags as
overwriting a previously unchecked errno value. fseek() to offset 0
is functionally equivalent without the implicit errno reset.
Replace rewind() with fseek(f, 0, SEEK_SET) in the test helper
function. rewind() internally clears errno, which scan-build flags
as overwriting a previously unchecked errno value. fseek() to
offset 0 is functionally equivalent without the implicit errno
reset.
@padelsbach padelsbach merged commit 6118655 into wolfSSL:master Apr 22, 2026
131 checks passed
@ejohnstown ejohnstown deleted the misc-static branch April 22, 2026 20:40
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