Skip to content

Commit bc7d795

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 5371e5e commit bc7d795

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

examples/echoserver/echoserver.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,22 +383,23 @@ 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);
393-
394-
if (ret == 0) {
394+
if (ret <= 0) {
395+
ret = -1;
396+
}
397+
else {
395398
name->sun_path[sizeof(name->sun_path) - 1] = '\0';
396399
size = WSTRLEN(name->sun_path) +
397400
offsetof(struct sockaddr_un, sun_path);
398401
ctx->listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
399-
if (ctx->listenFd == -1) {
400-
ret = -1;
401-
}
402+
ret = (ctx->listenFd == -1) ? -1 : 0;
402403
}
403404

404405
if (ret == 0) {
@@ -407,17 +408,29 @@ static int wolfSSH_AGENT_DefaultActions(WS_AgentCbAction action, void* vCtx)
407408
}
408409

409410
if (ret == 0) {
411+
nameBound = 1;
410412
ret = setenv(EnvNameAuthPort, name->sun_path, 1);
411413
}
412414

413415
if (ret == 0) {
416+
envSet = 1;
414417
ret = listen(ctx->listenFd, 5);
415418
}
416419

417420
if (ret == 0) {
418421
ctx->state = AGENT_STATE_LISTEN;
419422
}
420423
else {
424+
if (nameBound) {
425+
unlink(ctx->name.sun_path);
426+
}
427+
if (envSet) {
428+
unsetenv(EnvNameAuthPort);
429+
}
430+
if (ctx->listenFd >= 0) {
431+
close(ctx->listenFd);
432+
ctx->listenFd = -1;
433+
}
421434
ret = WS_AGENT_SETUP_E;
422435
}
423436
}

examples/portfwd/portfwd.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,25 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
404404
if (ret != WS_SUCCESS)
405405
err_sys("Couldn't connect SFTP");
406406

407+
if (readyFile != NULL) {
408+
#ifndef NO_FILESYSTEM
409+
WFILE* f = NULL;
410+
ret = WFOPEN(NULL, &f, readyFile, "w");
411+
if (f != NULL && ret == 0) {
412+
char portStr[10];
413+
int l;
414+
415+
l = WSNPRINTF(portStr, sizeof(portStr), "%d\n", (int)fwdFromPort);
416+
if (l > 0) {
417+
WFWRITE(NULL, portStr, MIN((size_t)l, sizeof(portStr)), 1, f);
418+
WFCLOSE(NULL, f);
419+
}
420+
}
421+
#else
422+
err_sys("cannot create readyFile with no file system.\r\n");
423+
#endif
424+
}
425+
407426
FD_ZERO(&templateFds);
408427
FD_SET(sshFd, &templateFds);
409428
FD_SET(listenFd, &templateFds);

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)