Skip to content

Fix DEADCODE and TOCTOU defects reported by Coverity - #1134

Merged
philljj merged 2 commits into
wolfSSL:masterfrom
ejohnstown:sf12
Jul 31, 2026
Merged

Fix DEADCODE and TOCTOU defects reported by Coverity#1134
philljj merged 2 commits into
wolfSSL:masterfrom
ejohnstown:sf12

Conversation

@ejohnstown

Copy link
Copy Markdown
Contributor

Coverity flagged two new defects:

  • CheckAlgoList() rejected "none" via a noneOk flag that was only ever set
    inside the WOLFSSH_ALLOW_NONE_CIPHER guard, so usableCount++ was
    unreachable in the default build. The whole ID_NONE arm now lives under
    the guard. Behavior is unchanged in both builds.
  • test_ConfigSavePID() stat()ed the PID path and then fopen()ed it.
    Scenarios 1 and 5 now fopen() once and fstat() that handle, so the mode
    asserted is the mode of the file the PID was read from. A failed open is
    a logged error rather than an indirect rd == 0.

The FIFO lstat() and the failPath existence test keep their path-based
checks: neither has a descriptor to stat, and mkdtemp() gives the test a
0700 directory.

Issues: CID-651701, CID-651702

- noneOk was only ever set inside the WOLFSSH_ALLOW_NONE_CIPHER guard,
  so usableCount++ was unreachable in the default build.
- Move the whole ID_NONE arm under the guard and drop noneOk. Behavior
  is unchanged in both builds.

Issues: CID-651702
- Scenarios 1 and 5 fopen() once and fstat() that handle instead of
  stat()ing the path a second time.
- A failed open is now a logged error rather than an indirect rd == 0.
- The FIFO lstat() and failPath existence test stay as they are: neither
  has a descriptor to stat, and mkdtemp()'s 0700 directory makes them
  unraceable.

Issues: CID-651701
Copilot AI review requested due to automatic review settings July 29, 2026 17:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 two Coverity-reported defects in wolfSSH: a DEADCODE issue in algorithm list validation and a TOCTOU-style test defect in wolfsshd PID file verification.

Changes:

  • Fixes unreachable usableCount++ logic for "none" by moving ID_NONE handling fully under WOLFSSH_ALLOW_NONE_CIPHER in CheckAlgoList().
  • Updates test_ConfigSavePID() to open PID files once and fstat() the opened handle (instead of stat() + fopen()), ensuring asserted mode matches the file actually read.

Reviewed changes

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

File Description
src/internal.c Makes "none" acceptance/rejection compile-time consistent and removes dead/unreachable logic in CheckAlgoList().
apps/wolfsshd/test/test_configuration.c Reworks PID file read+mode assertions to avoid path-based TOCTOU in the test by using fopen() + fstat().

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

@philljj
philljj self-requested a review July 31, 2026 16:00
@philljj philljj self-assigned this Jul 31, 2026
@philljj
philljj merged commit c39d555 into wolfSSL:master Jul 31, 2026
148 checks passed
@ejohnstown
ejohnstown deleted the sf12 branch July 31, 2026 16:12
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