Skip to content

Commit 7325678

Browse files
ejohnstownphilljj
authored andcommitted
echoserver: keep the EOF reply owed across a rekey
wolfSSH_ChannelIdRead() has no rekey guard, so a drained channel still reports zero mid-rekey and the drain loop calls the reply in. That send returns WS_REKEYING before it prepares a packet, so nothing is queued. - take the send's status instead of discarding it - latch eofAnswered and ChildRunning on every status but WS_REKEYING, so the reply is retried on a later pass; the KEX traffic wakes it - a short send is left latching: it bundled the EOF and set eofTxd, so a retry queues nothing and the loop would stall in an untimed select waiting on a peer that has already half-closed - same change in the Espressif copy
1 parent 7b17f65 commit 7325678

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,9 +1067,16 @@ static int ssh_worker(thread_ctx_t* threadCtx)
10671067
/* Only an emptied channel earns the EOF; anything
10681068
* else is retried on a later pass. */
10691069
if (eofDrained) {
1070-
wolfSSH_ChannelSendEof(eofChannel);
1071-
eofAnswered = 1;
1072-
ChildRunning = 0;
1070+
int eofRet;
1071+
1072+
eofRet = wolfSSH_ChannelSendEof(eofChannel);
1073+
/* A rekey queues nothing, so the reply is still
1074+
* owed and the KEX traffic wakes the next pass.
1075+
* A short send already bundled it. */
1076+
if (eofRet != WS_REKEYING) {
1077+
eofAnswered = 1;
1078+
ChildRunning = 0;
1079+
}
10731080
}
10741081
}
10751082
}

ide/Espressif/ESP-IDF/examples/wolfssh_echoserver/main/echoserver.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,9 +1051,16 @@ static int ssh_worker(thread_ctx_t* threadCtx)
10511051
/* Only an emptied channel earns the EOF; anything
10521052
* else is retried on a later pass. */
10531053
if (eofDrained) {
1054-
wolfSSH_ChannelSendEof(eofChannel);
1055-
eofAnswered = 1;
1056-
ChildRunning = 0;
1054+
int eofRet;
1055+
1056+
eofRet = wolfSSH_ChannelSendEof(eofChannel);
1057+
/* A rekey queues nothing, so the reply is still
1058+
* owed and the KEX traffic wakes the next pass.
1059+
* A short send already bundled it. */
1060+
if (eofRet != WS_REKEYING) {
1061+
eofAnswered = 1;
1062+
ChildRunning = 0;
1063+
}
10571064
}
10581065
}
10591066
}

0 commit comments

Comments
 (0)