Propagate only WANT_WRITE in DoKexInit - #1278
ejohnstown wants to merge 1 commit into
Conversation
DoKexInit() reports ssh->error once it has handled the KEXINIT, so a blocked reply reaches the caller. Report it only when it is WS_WANT_WRITE. Anything else in ssh->error is left by an earlier call, and a WS_WINDOW_FULL from SendChannelData() failed the peer's rekey. - tests/regress.c runs DoKexInit() with WS_SUCCESS, WS_WINDOW_FULL and WS_CHAN_RXD left in ssh->error, and with the reply send blocked. Issue: F-14394
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #1278
Scan targets checked: wolfssh-src, wolfssh-bugs
Coverage: 1 of 2 in-scope changed file(s) opened by the reviewer; not opened: tests/regress.c
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.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (5)
This overridesretunconditionally based onssh->error. Ifretalready contains a real… · New The new behavior still relies onssh->errorbeing specifically attributable toSendKexInit(). A… · New The new regression is fully gated byKEXDH_REPLY_REGRESS_KEX_ALGO. If this macro isn’t enabled in… · New The test doesn’t validate thatBuildKexInitPayload()succeeded. If it returns 0 (or an otherwise… · New Given the new logic explicitly propagatesWS_WANT_WRITE, it would be valuable to add a case where… · New
What changed in this PR
Updates DoKexInit() to only propagate WS_WANT_WRITE back to the caller (avoiding failures due to unrelated stale ssh->error values) and adds regression coverage around stale errors and blocked reply sends.
Changes:
- Limit
DoKexInit()error propagation toWS_WANT_WRITEonly. - Add a regression helper and test cases to validate stale
ssh->errorhandling and blocked send behavior. - Wire the new regression test into
main()under an existing compile-time guard.
| File | Description |
|---|---|
| tests/regress.c | Adds a regression harness/test to ensure stale ssh->error values don’t break peer rekey, while still reporting blocked reply sends. |
| src/internal.c | Changes DoKexInit() to propagate only WS_WANT_WRITE instead of any non-zero ssh->error. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| /* Propagate a want write from SendKexInit(). Only that: other | ||
| * codes in ssh->error are left by earlier calls, such as a | ||
| * WS_WINDOW_FULL from SendChannelData(), and would fail the | ||
| * key exchange. */ | ||
| if (ssh->error == WS_WANT_WRITE) | ||
| ret = WS_WANT_WRITE; |
| /* Propagate a want write from SendKexInit(). Only that: other | ||
| * codes in ssh->error are left by earlier calls, such as a | ||
| * WS_WINDOW_FULL from SendChannelData(), and would fail the | ||
| * key exchange. */ | ||
| if (ssh->error == WS_WANT_WRITE) | ||
| ret = WS_WANT_WRITE; |
| @@ -14859,6 +14859,75 @@ static void TestKexInitReservedNonZeroRejected(void) | |||
| wolfSSH_CTX_free(ctx); | |||
| } | |||
|
|
|||
| AssertIntEQ(wolfSSH_SetAlgoListKey(ssh, FPF_KEY_GOOD), WS_SUCCESS); | ||
|
|
||
| payloadSz = BuildKexInitPayload(ssh, FPF_KEX_GOOD, FPF_KEY_GOOD, | ||
| 0, payload, (word32)sizeof(payload)); |
| static void TestKexInitIgnoresStaleError(void) | ||
| { | ||
| AssertIntEQ(RunKexInitWithError(WS_SUCCESS, 0), WS_SUCCESS); | ||
| AssertIntEQ(RunKexInitWithError(WS_WINDOW_FULL, 0), WS_SUCCESS); | ||
| AssertIntEQ(RunKexInitWithError(WS_CHAN_RXD, 0), WS_SUCCESS); | ||
| /* A blocked reply is still reported. */ | ||
| AssertIntEQ(RunKexInitWithError(WS_SUCCESS, 1), WS_WANT_WRITE); | ||
| AssertIntEQ(RunKexInitWithError(WS_WINDOW_FULL, 1), WS_WANT_WRITE); | ||
| } |


DoKexInit() now reports ssh->error to its caller only when it is
WS_WANT_WRITE. A stale WS_WINDOW_FULL left by SendChannelData() no
longer fails the peer's rekey.
WS_CHAN_RXD, and a blocked reply send.
Issue: F-14394