Skip to content

Commit 441f975

Browse files
committed
Coverity: 'Constant' variable guards dead code
1. Remove the default password from the wolfSSH client app main function. It isn't set to anything. (It was originally an example client option.) 2. Remove handling the default password from the wolfSSH client app's user authentication callback. 3. Set the password size directly. 4. Changed a void typecast to WOLFSSH_UNUSED. Fixes CID: 572898
1 parent 538ae15 commit 441f975

2 files changed

Lines changed: 19 additions & 30 deletions

File tree

apps/wolfssh/common.c

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ int ClientUserAuth(byte authType,
499499
{
500500
int ret = WOLFSSH_USERAUTH_SUCCESS;
501501

502+
WOLFSSH_UNUSED(ctx);
503+
502504
#ifdef DEBUG_WOLFSSH
503505
/* inspect supported types from server */
504506
printf("Server supports:\n");
@@ -538,37 +540,28 @@ int ClientUserAuth(byte authType,
538540
ret = WOLFSSH_USERAUTH_SUCCESS;
539541
}
540542
else if (authType == WOLFSSH_USERAUTH_PASSWORD) {
541-
const char* defaultPassword = (const char*)ctx;
542-
word32 passwordSz = 0;
543-
544-
if (defaultPassword != NULL) {
545-
passwordSz = (word32)strlen(defaultPassword);
546-
WMEMCPY(userPassword, defaultPassword, passwordSz);
543+
printf("Password: ");
544+
fflush(stdout);
545+
ClientSetEcho(0);
546+
if (fgets((char*)userPassword, sizeof(userPassword), stdin) == NULL) {
547+
fprintf(stderr, "Getting password failed.\n");
548+
ret = WOLFSSH_USERAUTH_FAILURE;
547549
}
548550
else {
549-
printf("Password: ");
550-
fflush(stdout);
551-
ClientSetEcho(0);
552-
if (fgets((char*)userPassword, sizeof(userPassword), stdin) == NULL) {
553-
fprintf(stderr, "Getting password failed.\n");
554-
ret = WOLFSSH_USERAUTH_FAILURE;
555-
}
556-
else {
557-
char* c = strpbrk((char*)userPassword, "\r\n");
558-
if (c != NULL)
559-
*c = '\0';
560-
}
561-
passwordSz = (word32)strlen((const char*)userPassword);
562-
ClientSetEcho(1);
563-
#ifdef USE_WINDOWS_API
564-
printf("\r\n");
565-
#endif
566-
fflush(stdout);
551+
char* c = strpbrk((char*)userPassword, "\r\n");
552+
if (c != NULL)
553+
*c = '\0';
567554
}
555+
ClientSetEcho(1);
556+
#ifdef USE_WINDOWS_API
557+
printf("\r\n");
558+
#endif
559+
fflush(stdout);
568560

569561
if (ret == WOLFSSH_USERAUTH_SUCCESS) {
570562
authData->sf.password.password = userPassword;
571-
authData->sf.password.passwordSz = passwordSz;
563+
authData->sf.password.passwordSz =
564+
(word32)strlen((const char*)userPassword);
572565
}
573566
}
574567

@@ -743,7 +736,7 @@ int ClientLoadCA(WOLFSSH_CTX* ctx, const char* caCert)
743736
WFREE(der, NULL, 0);
744737
}
745738
#else
746-
(void)ctx;
739+
WOLFSSH_UNUSED(ctx);
747740
fprintf(stderr, "Support for certificates not compiled in.");
748741
ret = WS_NOT_COMPILED;
749742
#endif

apps/wolfssh/wolfssh.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,6 @@ static THREAD_RETURN WOLFSSH_THREAD wolfSSH_Client(void* args)
900900
SOCKADDR_IN_T clientAddr;
901901
socklen_t clientAddrSz = sizeof(clientAddr);
902902
int ret = 0;
903-
const char* password = NULL;
904903
byte keepOpen = 1;
905904
#ifdef USE_WINDOWS_API
906905
byte rawMode = 0;
@@ -976,9 +975,6 @@ static THREAD_RETURN WOLFSSH_THREAD wolfSSH_Client(void* args)
976975
wolfSSH_SetGlobalReqCtx(ssh, &ssh); /* dummy ctx */
977976
#endif
978977

979-
if (password != NULL)
980-
wolfSSH_SetUserAuthCtx(ssh, (void*)password);
981-
982978
#ifdef WOLFSSH_AGENT
983979
if (useAgent) {
984980
WMEMSET(&agentCbCtx, 0, sizeof(agentCbCtx));

0 commit comments

Comments
 (0)