Skip to content

Commit 5cd81c9

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. Better cleanup of agent startup failures.
1 parent a2e6556 commit 5cd81c9

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

examples/echoserver/echoserver.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,22 +383,24 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
383383
if (action == WOLFSSH_AGENT_LOCAL_SETUP) {
384384
struct sockaddr_un* name = &ctx->name;
385385
size_t size;
386+
int envSet = 0, nameBound = 0;
386387

387388
WMEMSET(name, 0, sizeof(struct sockaddr_un));
388389
ctx->pid = getpid();
389390
name->sun_family = AF_LOCAL;
390391

391392
ret = snprintf(name->sun_path, sizeof(name->sun_path),
392393
"/tmp/wolfserver.%d", ctx->pid);
394+
if (ret >= 0) {
395+
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
396+
size = WSTRLEN(name->sun_path);
397+
ret = (size < WSTRLEN("/tmp/wolfserver."));
398+
}
393399

394400
if (ret == 0) {
395-
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
396-
size = WSTRLEN(name->sun_path) +
397-
offsetof(struct sockaddr_un, sun_path);
401+
size += offsetof(struct sockaddr_un, sun_path);
398402
ctx->listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
399-
if (ctx->listenFd == -1) {
400-
ret = -1;
401-
}
403+
ret = (ctx->listenFd == -1) ? -1 : 0;
402404
}
403405

404406
if (ret == 0) {
@@ -407,17 +409,29 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
407409
}
408410

409411
if (ret == 0) {
412+
nameBound = 1;
410413
ret = setenv(EnvNameAuthPort, name->sun_path, 1);
411414
}
412415

413416
if (ret == 0) {
417+
envSet = 1;
414418
ret = listen(ctx->listenFd, 5);
415419
}
416420

417421
if (ret == 0) {
418422
ctx->state = AGENT_STATE_LISTEN;
419423
}
420424
else {
425+
if (nameBound) {
426+
unlink(ctx->name.sun_path);
427+
}
428+
if (envSet) {
429+
unsetenv(EnvNameAuthPort);
430+
}
431+
if (ctx->listenFd >= 0) {
432+
close(ctx->listenFd);
433+
ctx->listenFd = -1;
434+
}
421435
ret = WS_AGENT_SETUP_E;
422436
}
423437
}

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)