Skip to content

Commit f18c692

Browse files
committed
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. Remove the size variable and just use sizeof() the sockaddr_un. Better cleanup of agent startup failures.
1 parent 05658ab commit f18c692

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

examples/echoserver/echoserver.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
382382

383383
if (action == WOLFSSH_AGENT_LOCAL_SETUP) {
384384
struct sockaddr_un* name = &ctx->name;
385-
size_t size;
385+
int envSet = 0;
386386

387387
WMEMSET(name, 0, sizeof(struct sockaddr_un));
388388
ctx->pid = getpid();
@@ -391,33 +391,37 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
391391
ret = snprintf(name->sun_path, sizeof(name->sun_path),
392392
"/tmp/wolfserver.%d", ctx->pid);
393393

394-
if (ret == 0) {
394+
if (ret > 0) {
395395
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
396-
size = WSTRLEN(name->sun_path) +
397-
offsetof(struct sockaddr_un, sun_path);
398396
ctx->listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
399-
if (ctx->listenFd == -1) {
400-
ret = -1;
401-
}
397+
ret = (ctx->listenFd == -1) ? -1 : 0;
402398
}
403399

404400
if (ret == 0) {
405-
ret = bind(ctx->listenFd,
406-
(struct sockaddr *)name, (socklen_t)size);
401+
ret = bind(ctx->listenFd, (struct sockaddr *)name,
402+
(socklen_t)sizeof(struct sockaddr_un));
407403
}
408404

409405
if (ret == 0) {
410406
ret = setenv(EnvNameAuthPort, name->sun_path, 1);
411407
}
412408

413409
if (ret == 0) {
410+
envSet = 1;
414411
ret = listen(ctx->listenFd, 5);
415412
}
416413

417414
if (ret == 0) {
418415
ctx->state = AGENT_STATE_LISTEN;
419416
}
420417
else {
418+
if (envSet) {
419+
unsetenv(EnvNameAuthPort);
420+
}
421+
if (ctx->listenFd >= 0) {
422+
close(ctx->listenFd);
423+
ctx->listenFd = -1;
424+
}
421425
ret = WS_AGENT_SETUP_E;
422426
}
423427
}

src/agent.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ static int PostLock(WOLFSSH_AGENT_CTX* agent,
374374
word32 ppSz;
375375

376376
WLOG(WS_LOG_AGENT, "Posting lock to agent %p", agent);
377+
WOLFSSH_UNUSED(agent);
377378

378379
ppSz = sizeof(pp) - 1;
379380
if (passphraseSz < ppSz)
@@ -395,6 +396,7 @@ static int PostUnlock(WOLFSSH_AGENT_CTX* agent,
395396
word32 ppSz;
396397

397398
WLOG(WS_LOG_AGENT, "Posting unlock to agent %p", agent);
399+
WOLFSSH_UNUSED(agent);
398400

399401
ppSz = sizeof(pp) - 1;
400402
if (passphraseSz < ppSz)

0 commit comments

Comments
 (0)