Skip to content

tidy clang-tidy#1002

Open
ejohnstown wants to merge 6 commits into
wolfSSL:masterfrom
ejohnstown:tidy-tidy
Open

tidy clang-tidy#1002
ejohnstown wants to merge 6 commits into
wolfSSL:masterfrom
ejohnstown:tidy-tidy

Conversation

@ejohnstown
Copy link
Copy Markdown
Contributor

Clean up clang-tidy findings across wolfSSH. The checks set initially flagged 378 issues across six categories; this branch clears all of them. Build is clean (exit 0); no functional or wire-protocol changes.

  • Add parameter names to function declarations -- name the parameters in public/internal-header function decls and the few forward decls in .c files; clears all 360 readability-named-parameter findings. Prototypes that exceeded 80 columns after the names were added are re-wrapped using the existing 8-space continuation style.
  • Remove redundant preprocessor guard -- drop the inner #ifdef WOLFSSH_CERTS inside DoUserAuthRequestRsaCert (the surrounding function is already under the same guard); clears readability-redundant-preprocessor.
  • Move unsafe call out of signal handler -- drop fprintf from wolfsshd's interruptCatch and log "Closing down wolfSSHD" from the main accept loop after quit is observed; annotate sftpclient's wolfSSH_SFTP_Interrupt call with NOLINT since it is a single byte store; clears both bugprone-signal-handler findings.
  • Use reentrant time conversion in SFTP -- SFTP_CreateLongName switches from XGMTIME (gmtime) to WLOCALTIME, which expands to gmtime_r/localtime_r/localtime_s per platform; clears concurrency-mt-unsafe.
  • Tighten SCP timestamp bounds check -- in ParseTimestamp, move ++idx out of the || conditions and tighten the bound from > bufSz to >= bufSz; clears both bugprone-inc-dec-in-conditions findings and fixes a one-past-the-end read.
  • Bound sshd Include directive recursion -- track include depth on WOLFSSHD_CONFIG, reject loads past WOLFSSHD_MAX_INCLUDE_DEPTH (16), and annotate the four functions in the include cycle with NOLINTNEXTLINE pointing at the bound; clears all 8 misc-no-recursion findings.

Copilot AI review requested due to automatic review settings June 4, 2026 21:13
@ejohnstown ejohnstown requested a review from padelsbach June 4, 2026 21:13
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 is a clang-tidy cleanup pass across wolfSSH, focused on eliminating diagnostics (primarily readability-named-parameter) while also addressing a few correctness/safety findings (signal-handler safety, SFTP time conversion reentrancy, SCP bounds check, and sshd config include recursion).

Changes:

  • Add parameter names to many public/internal header prototypes and a few forward declarations, rewrapping long prototypes to match existing continuation style.
  • Improve safety/correctness in a few targeted areas: remove redundant preprocessor guarding, avoid logging from a signal handler, use reentrant time conversion for SFTP longname creation, and tighten an SCP timestamp bounds check.
  • Bound Include recursion in wolfsshd configuration loading via a tracked include depth and a maximum depth constant.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
wolfssh/wolfscp.h Names parameters in SCP API declarations; rewraps long prototypes.
wolfssh/ssh.h Names parameters in core public API declarations and callback setters.
wolfssh/port.h Names parameters for select portability-layer prototypes (stdio + string + pread/pwrite).
wolfssh/log.h Names parameters in the public logging API signature.
wolfssh/internal.h Names parameters in internal APIs (channels, I/O handlers, packet helpers, SCP helpers).
wolfssh/agent.h Names parameters in agent API/internal declarations and rewraps long prototypes.
src/wolfsftp.c Switches SFTP longname time conversion to WLOCALTIME and simplifies preprocessor guards.
src/wolfscp.c Refactors SCP timestamp parsing to avoid inc/dec inside conditions and tightens bounds.
src/log.c Updates default logging callback forward-declaration parameter names/wrapping.
src/internal.c Removes redundant inner #ifdef WOLFSSH_CERTS inside an already-guarded function.
examples/sftpclient/sftpclient.c Annotates wolfSSH_SFTP_Interrupt() call in signal handler with NOLINT.
examples/scpclient/scpclient.h Names the thread entry parameter in the example header prototype.
apps/wolfsshd/wolfsshd.c Removes fprintf from signal handler; logs shutdown message from main loop.
apps/wolfsshd/test/test_configuration.c Names the fmt parameter in the test logger prototype.
apps/wolfsshd/configuration.c Adds include-depth tracking + maximum recursion bound; annotates bounded recursion with NOLINTNEXTLINE.

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

Comment thread wolfssh/port.h Outdated
Comment thread src/wolfsftp.c
Comment thread apps/wolfsshd/configuration.c
Clean up clang-tidy readability-named-parameter findings
across wolfSSH headers and sources.
Cleanup clang-tidy readability-redundant-preprocessor finding.
Cleanup clang-tidy bugprone-signal-handler findings.
- wolfsshd: drop fprintf from interruptCatch; the main accept
  loop logs "Closing down wolfSSHD" after seeing quit set.
- sftpclient: annotate wolfSSH_SFTP_Interrupt call in
  sig_handler with NOLINT, since the function is only a single
  byte store and is safe to call from a signal handler.
Cleanup clang-tidy concurrency-mt-unsafe finding.

- SFTP_CreateLongName: switch from XGMTIME (gmtime) to
  WLOCALTIME, which expands to gmtime_r/localtime_r/
  localtime_s per platform.
Cleanup clang-tidy bugprone-inc-dec-in-conditions finding.

- ParseTimestamp: move ++idx out of the || conditions
  and tighten the bound from > bufSz to >= bufSz.
Cleanup clang-tidy misc-no-recursion finding.

- wolfSSHD_ConfigLoad: track depth on WOLFSSHD_CONFIG
  and reject loads past WOLFSSHD_MAX_INCLUDE_DEPTH (16).
- HandleInclude, HandleConfigOption, ParseConfigLine,
  wolfSSHD_ConfigLoad: annotate the call cycle with
  NOLINTNEXTLINE pointing at the bound.
- Add a recursive configuration test.

/* create new configure for altered options specific to the match */
if (ret == WS_SUCCESS) {
newConf = wolfSSHD_ConfigCopy(*conf);
Copy link
Copy Markdown
Contributor

@padelsbach padelsbach Jun 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI tells me wolfSSHD_ConfigCopy does not copy the includeDepth param, and thus could be wiped out here, partially defeating the purpose of this commit. Should we copy that field?

Comment thread src/wolfsftp.c
* wrapper so the shared static buffer behind gmtime() is
* not used. */
mtime = (time_t)atr->mtime;
if (!WLOCALTIME(&mtime, &localTime)) {
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.

This switches from UTC time to local time in all platforms except Zephyr which uses gmtime_r (in port.h). Is this ok?

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