Repository navigation
echoserver: unwind all echoserver_test() failures - #1379
ejohnstown wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The mutex initialization return value is unchecked, so a failed initialization still sets doneLockInit and can cause startup error cleanup to free an uninitialized mutex.
1 open issue
What changed in this PR
This PR routes echoserver_test() failures through a shared cleanup path to prevent resource leaks in the in-process test harness.
Changes:
- Tracks initialization and releases resources on failure while preserving
MY_EX_USAGEfor usage errors. - Frees connection resources before unwinding selected setup failures.
- Adds API tests for usage, algorithm-list, and key-load failures, intended to run under a leak checker.
| File | Description |
|---|---|
| tests/api.c | Adds startup-failure cleanup regression tests. |
| examples/echoserver/echoserver.c | Centralizes failure cleanup and tracks initialized resources. |
Review effort: Balanced
ES_ERROR now jumps to an echoserverFail label instead of returning, and the label frees whatever is set up at that point: the listen socket, unconsumed option lists, keyboard prompts, doneLock, pwMapList, the CTX, the TPM host key and wolfSSH_Init(). The test harness keeps running after echoserver_test() returns, so these were live-process leaks. - pwMapList and kbAuthData are zeroed on entry; flags track doneLock and wolfSSH_Init(), each set only once its init succeeds - usage errors take the same path and keep MY_EX_USAGE - loop failures free their ssh and thread context before the jump - drop the inline frees the cert-store and prompt paths now duplicate - api.c: drive usage, algo-list and key-load failures for LSan; the key-load case is skipped on Zephyr and Nucleus, which lack -j Issue: F-17053
8084ecb to
7817d12
Compare
|
@claude review |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1379
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 2 of 2 in-scope changed file(s) opened by the reviewer
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
There was a problem hiding this comment.
LGTM. The single cleanup label in echoserver_test() is correct and doesn't double-free anything along any of the paths I traced.
What was reviewed:
- Every
ES_ERRORpath, from the usage error through the accept loop. Each one jumps toechoserverFailwith the state it needs already set:pwMapListandkbAuthDataare zeroed on entry,ctx/listenFdstart as NULL/invalid, and the mutex andwolfSSH_Initare guarded by flags. - Double frees ruled out. The option lists are set to NULL after they're consumed, the old inline prompt and cert-store frees are gone, and the paths that still free
keyLoadBuf, orsshandthreadCtx, do so only before the jump. - Freeing
ctxfrom inside the accept loop is safe becauseserver_workerruns inline, not on a separate thread.EchoserverCleanupTpmHostKeydoes nothing when no TPM key was loaded, and callingwolfSSH_Cleanupfrom the test is balanced becausewolfCrypt_Initis reference-counted.
Extended reasoning...
The change touches only the example echoserver (examples/echoserver/echoserver.c) and adds an API test (tests/api.c). It doesn't change any library code or any security-sensitive surface such as auth or crypto logic. It moves echoserver_test()'s error handling to a single goto-based cleanup label, and every resource it frees there is either initialized up front or guarded by a flag. The only earlier inline comment, from an automated reviewer at the wc_InitMutex line, was followed by a commit that now checks that call's return value. The bug hunt ran to completion (dry_streak) with no findings.

Every echoserver_test() failure goes through one cleanup label that
frees what is set up so far, so the in-process test harness no longer
leaks on a startup error.
Issue: F-17053