Skip to content

Commit 20ace73

Browse files
fix new scan-build warning
1 parent 3f52af5 commit 20ace73

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

apps/wolfsshd/wolfsshd.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,11 @@ int main(int argc, char** argv)
780780

781781
case 'p':
782782
if (ret == WS_SUCCESS) {
783+
if (myoptarg == NULL) {
784+
ret = WS_BAD_ARGUMENT;
785+
break;
786+
}
787+
783788
ret = XATOI(myoptarg);
784789
if (ret < 0) {
785790
fprintf(stderr, "Issue parsing port number %s\n",

examples/echoserver/echoserver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
747747
if (agentListenFd > maxFd)
748748
maxFd = agentListenFd;
749749
}
750-
if (threadCtx->agentCbCtx.state == AGENT_STATE_CONNECTED) {
750+
if (agentFd >= 0 && threadCtx->agentCbCtx.state == AGENT_STATE_CONNECTED) {
751751
FD_SET(agentFd, &readFds);
752752
if (agentFd > maxFd)
753753
maxFd = agentFd;
@@ -759,7 +759,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
759759
if (fwdListenFd > maxFd)
760760
maxFd = fwdListenFd;
761761
}
762-
if (threadCtx->fwdCbCtx.state == FWD_STATE_CONNECTED) {
762+
if (fwdFd >= 0 && threadCtx->fwdCbCtx.state == FWD_STATE_CONNECTED) {
763763
FD_SET(fwdFd, &readFds);
764764
if (fwdFd > maxFd)
765765
maxFd = fwdFd;
@@ -918,7 +918,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
918918
}
919919
#endif
920920
#ifdef WOLFSSH_AGENT
921-
if (threadCtx->agentCbCtx.state == AGENT_STATE_CONNECTED) {
921+
if (agentFd >= 0 && threadCtx->agentCbCtx.state == AGENT_STATE_CONNECTED) {
922922
if (FD_ISSET(agentFd, &readFds)) {
923923
#ifdef SHELL_DEBUG
924924
printf("agentFd set in readfd\n");
@@ -979,7 +979,7 @@ static int ssh_worker(thread_ctx_t* threadCtx)
979979
}
980980
#endif
981981
#ifdef WOLFSSH_FWD
982-
if (threadCtx->fwdCbCtx.state == FWD_STATE_CONNECTED) {
982+
if (fwdFd >= 0 && threadCtx->fwdCbCtx.state == FWD_STATE_CONNECTED) {
983983
if (FD_ISSET(fwdFd, &readFds)) {
984984
#ifdef SHELL_DEBUG
985985
printf("fwdFd set in readfd\n");

examples/portfwd/portfwd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ THREAD_RETURN WOLFSSH_THREAD portfwd_worker(void* args)
271271
break;
272272

273273
case 'p':
274+
if (myoptarg == NULL)
275+
err_sys("null argument found");
274276
port = (word16)atoi(myoptarg);
275277
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
276278
if (port == 0)

examples/scpclient/scpclient.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
277277
break;
278278

279279
case 'p':
280+
if (myoptarg == NULL)
281+
err_sys("null argument found");
282+
280283
port = (word16)atoi(myoptarg);
281284
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
282285
if (port == 0)

examples/sftpclient/sftpclient.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,8 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args)
13611361
break;
13621362

13631363
case 'p':
1364+
if (myoptarg == NULL)
1365+
err_sys("null argument found");
13641366
port = (word16)atoi(myoptarg);
13651367
#if !defined(NO_MAIN_DRIVER) || defined(USE_WINDOWS_API)
13661368
if (port == 0)

0 commit comments

Comments
 (0)