Skip to content

Commit d43dfd5

Browse files
ejohnstownpadelsbach
authored andcommitted
Coverity: Uninitialized scalar variable
1. Remove the check on authType, it is covered already. 2. Add Keyboard Setup to the existing check on authType. 3. Add a branch for User Auth None so it reaches its handler in the map loop rather than the new error case. 4. Add else case for an error. Fixes CID: 637345
1 parent 36e2765 commit d43dfd5

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,7 +2293,7 @@ static int wsUserAuth(byte authType,
22932293
{
22942294
PwMapList* list;
22952295
PwMap* map;
2296-
byte authHash[WC_SHA256_DIGEST_SIZE];
2296+
byte authHash[WC_SHA256_DIGEST_SIZE] = {0};
22972297

22982298
if (ctx == NULL) {
22992299
fprintf(stderr, "wsUserAuth: ctx not set");
@@ -2306,19 +2306,6 @@ static int wsUserAuth(byte authType,
23062306
return WOLFSSH_USERAUTH_WOULD_BLOCK;
23072307
}
23082308

2309-
if (authType != WOLFSSH_USERAUTH_PASSWORD &&
2310-
#ifdef WOLFSSH_ALLOW_USERAUTH_NONE
2311-
authType != WOLFSSH_USERAUTH_NONE &&
2312-
#endif
2313-
#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
2314-
authType != WOLFSSH_USERAUTH_KEYBOARD &&
2315-
authType != WOLFSSH_USERAUTH_KEYBOARD_SETUP &&
2316-
#endif
2317-
authType != WOLFSSH_USERAUTH_PUBLICKEY) {
2318-
2319-
return WOLFSSH_USERAUTH_FAILURE;
2320-
}
2321-
23222309
if (authType == WOLFSSH_USERAUTH_PASSWORD) {
23232310
wc_Sha256Hash(authData->sf.password.password,
23242311
authData->sf.password.passwordSz,
@@ -2333,6 +2320,9 @@ static int wsUserAuth(byte authType,
23332320
authData->sf.keyboard.responseLengths[0],
23342321
authHash);
23352322
}
2323+
else if (authType == WOLFSSH_USERAUTH_KEYBOARD_SETUP) {
2324+
/* Do nothing. */
2325+
}
23362326
#endif
23372327
else if (authType == WOLFSSH_USERAUTH_PUBLICKEY) {
23382328
wc_Sha256Hash(authData->sf.publicKey.publicKey,
@@ -2406,6 +2396,14 @@ static int wsUserAuth(byte authType,
24062396
}
24072397
#endif /* WOLFSSH_CERTS && !WOLFSSH_NO_FPKI */
24082398
}
2399+
#ifdef WOLFSSH_ALLOW_USERAUTH_NONE
2400+
else if (authType == WOLFSSH_USERAUTH_NONE) {
2401+
/* Handled in the map loop below. */
2402+
}
2403+
#endif
2404+
else {
2405+
return WOLFSSH_USERAUTH_INVALID_AUTHTYPE;
2406+
}
24092407

24102408
list = (PwMapList*)ctx;
24112409
map = list->head;

0 commit comments

Comments
 (0)