Skip to content

Commit fc39ced

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.
1 parent 05658ab commit fc39ced

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

examples/echoserver/echoserver.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ 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;
386385

387386
WMEMSET(name, 0, sizeof(struct sockaddr_un));
388387
ctx->pid = getpid();
@@ -391,19 +390,15 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
391390
ret = snprintf(name->sun_path, sizeof(name->sun_path),
392391
"/tmp/wolfserver.%d", ctx->pid);
393392

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

404399
if (ret == 0) {
405-
ret = bind(ctx->listenFd,
406-
(struct sockaddr *)name, (socklen_t)size);
400+
ret = bind(ctx->listenFd, (struct sockaddr *)name,
401+
(socklen_t)sizeof(struct sockaddr_un));
407402
}
408403

409404
if (ret == 0) {

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)