mirror of https://github.com/wolfSSL/wolfssh.git
espressif: retire the forward fd at every close
Recording the direct forward's socket in the context left the two sites that close it on the target's own EOF or reset holding a stale copy, so the cleanup handler closed a descriptor number the task had since reissued. Every close now retires both the worker's copy and the context's, as the reference example does. - clear appFd where a zero read ends the forward - clear appFd and the worker's own fwdFd on a reset, which that branch never reset - compare appFd against a cast -1 in both places, since WS_SOCKET_T is unsigned on Windowspull/1255/head
parent
9c9f684321
commit
f4daee5ac3
|
|
@ -1162,7 +1162,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
|
|||
* the id it retired. */
|
||||
wolfSSH_GetLastRxId(ssh, &lastChannel);
|
||||
if (lastChannel == threadCtx->fwdCbCtx.channelId) {
|
||||
if (threadCtx->fwdCbCtx.appFd == -1) {
|
||||
if (threadCtx->fwdCbCtx.appFd == (WS_SOCKET_T)-1) {
|
||||
/* The cleanup handler ran ahead of this and
|
||||
* closed the socket; only this copy of the
|
||||
* descriptor is stale. */
|
||||
|
|
@ -1312,6 +1312,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
|
|||
to listening. */
|
||||
WCLOSESOCKET(fwdFd);
|
||||
fwdFd = -1;
|
||||
threadCtx->fwdCbCtx.appFd = -1;
|
||||
if (threadCtx->fwdCbCtx.hostName != NULL) {
|
||||
WFREE(threadCtx->fwdCbCtx.hostName,
|
||||
NULL, 0);
|
||||
|
|
@ -1332,6 +1333,8 @@ static int ssh_worker(thread_ctx_t* threadCtx)
|
|||
/* Connection reset. Socket is closed.
|
||||
* Go back to listening. */
|
||||
WCLOSESOCKET(fwdFd);
|
||||
fwdFd = -1;
|
||||
threadCtx->fwdCbCtx.appFd = -1;
|
||||
threadCtx->fwdCbCtx.state = FWD_STATE_LISTEN;
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue