Agent Update

1. Fix a couple unused variable warnings.
2. In wolfSSH_AGENT_DefaultActions(), fix comparison to the result of
   snprintf() treating normal result as an error. Reset the return code
   for the error state of the socket() command. Better cleanup of agent
   startup failures.
pull/874/head
John Safranek 2026-02-03 19:52:00 -08:00
parent a2e6556a1a
commit 5cd81c9f1f
2 changed files with 22 additions and 6 deletions

View File

@ -383,6 +383,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, nameBound = 0;
WMEMSET(name, 0, sizeof(struct sockaddr_un));
ctx->pid = getpid();
@ -390,15 +391,16 @@ 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) {
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
size = WSTRLEN(name->sun_path);
ret = (size < WSTRLEN("/tmp/wolfserver."));
}
if (ret == 0) {
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
size = WSTRLEN(name->sun_path) +
offsetof(struct sockaddr_un, sun_path);
size += 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) {
@ -407,10 +409,12 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
}
if (ret == 0) {
nameBound = 1;
ret = setenv(EnvNameAuthPort, name->sun_path, 1);
}
if (ret == 0) {
envSet = 1;
ret = listen(ctx->listenFd, 5);
}
@ -418,6 +422,16 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
ctx->state = AGENT_STATE_LISTEN;
}
else {
if (nameBound) {
unlink(ctx->name.sun_path);
}
if (envSet) {
unsetenv(EnvNameAuthPort);
}
if (ctx->listenFd >= 0) {
close(ctx->listenFd);
ctx->listenFd = -1;
}
ret = WS_AGENT_SETUP_E;
}
}

View File

@ -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)