mirror of https://github.com/wolfSSL/wolfssh.git
espressif: guard the forward cleanup handler
WOLFSSH_FWD_LOCAL_CLEANUP now runs, so this echoserver's handler for it runs too. It closes only the socket belonging to the channel that ended, and only when one was connected. - gate the handler on the channel id the library passes in the port parameter. A channel can outlive its turn in the single forwarding slot, and a cleanup arriving late would close the next one's socket - guard the close: the open can fail after the setup, with nothing yet connected and appFd still -1
parent
2b5855922f
commit
ffb4a0f2ec
|
|
@ -510,16 +510,23 @@ static int wolfSSH_FwdDefaultActions(WS_FwdCbAction action, void* vCtx,
|
|||
ctx->state = FWD_STATE_DIRECT;
|
||||
}
|
||||
else if (action == WOLFSSH_FWD_LOCAL_CLEANUP) {
|
||||
WCLOSESOCKET(ctx->appFd);
|
||||
if (ctx->hostName) {
|
||||
WFREE(ctx->hostName, NULL, 0);
|
||||
ctx->hostName = NULL;
|
||||
/* Channel id rides in port. Only its holder may tear the slot down. */
|
||||
if (port == ctx->channelId) {
|
||||
/* The open can fail after setup, before anything connected. */
|
||||
if (ctx->appFd != (WS_SOCKET_T)-1) {
|
||||
WCLOSESOCKET(ctx->appFd);
|
||||
ctx->appFd = -1;
|
||||
}
|
||||
if (ctx->hostName) {
|
||||
WFREE(ctx->hostName, NULL, 0);
|
||||
ctx->hostName = NULL;
|
||||
}
|
||||
if (ctx->originName) {
|
||||
WFREE(ctx->originName, NULL, 0);
|
||||
ctx->originName = NULL;
|
||||
}
|
||||
ctx->state = FWD_STATE_INIT;
|
||||
}
|
||||
if (ctx->originName) {
|
||||
WFREE(ctx->originName, NULL, 0);
|
||||
ctx->originName = NULL;
|
||||
}
|
||||
ctx->state = FWD_STATE_INIT;
|
||||
}
|
||||
else if (action == WOLFSSH_FWD_REMOTE_SETUP) {
|
||||
struct sockaddr_in addr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue