diff --git a/examples/echoserver/echoserver.c b/examples/echoserver/echoserver.c index cbf2662b4..b0d9be88f 100644 --- a/examples/echoserver/echoserver.c +++ b/examples/echoserver/echoserver.c @@ -382,7 +382,7 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx) if (action == WOLFSSH_AGENT_LOCAL_SETUP) { struct sockaddr_un* name = &ctx->name; - size_t size; + int envSet = 0; WMEMSET(name, 0, sizeof(struct sockaddr_un)); ctx->pid = getpid(); @@ -391,19 +391,15 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx) ret = snprintf(name->sun_path, sizeof(name->sun_path), "/tmp/wolfserver.%d", ctx->pid); - if (ret == 0) { + if (ret > 0) { name->sun_path[sizeof(name->sun_path) - 1] = '\0'; - size = WSTRLEN(name->sun_path) + - offsetof(struct sockaddr_un, sun_path); ctx->listenFd = socket(AF_UNIX, SOCK_STREAM, 0); - if (ctx->listenFd == -1) { - ret = -1; - } + ret = (ctx->listenFd == -1) ? -1 : 0; } if (ret == 0) { - ret = bind(ctx->listenFd, - (struct sockaddr *)name, (socklen_t)size); + ret = bind(ctx->listenFd, (struct sockaddr *)name, + (socklen_t)sizeof(struct sockaddr_un)); } if (ret == 0) { @@ -411,6 +407,7 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx) } if (ret == 0) { + envSet = 1; ret = listen(ctx->listenFd, 5); } @@ -418,6 +415,13 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx) ctx->state = AGENT_STATE_LISTEN; } else { + if (envSet) { + unsetenv(EnvNameAuthPort); + } + if (ctx->listenFd >= 0) { + close(ctx->listenFd); + ctx->listenFd = -1; + } ret = WS_AGENT_SETUP_E; } } diff --git a/src/agent.c b/src/agent.c index de918769c..bed5bd836 100644 --- a/src/agent.c +++ b/src/agent.c @@ -374,6 +374,7 @@ static int PostLock(WOLFSSH_AGENT_CTX* agent, word32 ppSz; WLOG(WS_LOG_AGENT, "Posting lock to agent %p", agent); + WOLFSSH_UNUSED(agent); ppSz = sizeof(pp) - 1; if (passphraseSz < ppSz) @@ -395,6 +396,7 @@ static int PostUnlock(WOLFSSH_AGENT_CTX* agent, word32 ppSz; WLOG(WS_LOG_AGENT, "Posting unlock to agent %p", agent); + WOLFSSH_UNUSED(agent); ppSz = sizeof(pp) - 1; if (passphraseSz < ppSz) diff --git a/src/ssh.c b/src/ssh.c index c30d5fd4a..c6d7508c0 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -2605,7 +2605,7 @@ int wolfSSH_worker(WOLFSSH* ssh, word32* channelId) } #endif /* WOLFSSH_TEST_BLOCK */ - if (ret == WS_SUCCESS) { + if (ret == WS_SUCCESS || ret == WS_CHAN_RXD) { if (channelId != NULL) { *channelId = ssh->lastRxId; }