@@ -3988,6 +3988,9 @@ static word32 AlgoListSz(const char* algoList)
39883988{
39893989 word32 algoListSz;
39903990
3991+ if (algoList == NULL)
3992+ return 0;
3993+
39913994 algoListSz = (word32)WSTRLEN(algoList);
39923995 if (algoList[algoListSz-1] == ',') {
39933996 --algoListSz;
@@ -13318,7 +13321,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1331813321 begin += LENGTH_SZ;
1331913322 WMEMCPY(output + begin, authData->sf.keyboard.promptName, slen);
1332013323 begin += slen;
13321- } else {
13324+ }
13325+ else {
1332213326 c32toa(0, output + begin);
1332313327 begin += LENGTH_SZ;
1332413328 }
@@ -13328,7 +13332,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1332813332 begin += LENGTH_SZ;
1332913333 WMEMCPY(output + begin, authData->sf.keyboard.promptInstruction, slen);
1333013334 begin += slen;
13331- } else {
13335+ }
13336+ else {
1333213337 c32toa(0, output + begin);
1333313338 begin += LENGTH_SZ;
1333413339 }
@@ -13338,7 +13343,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1333813343 begin += LENGTH_SZ;
1333913344 WMEMCPY(output + begin, authData->sf.keyboard.promptLanguage, slen);
1334013345 begin += slen;
13341- } else {
13346+ }
13347+ else {
1334213348 c32toa(0, output + begin);
1334313349 begin += LENGTH_SZ;
1334413350 }
@@ -13370,33 +13376,38 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1337013376 WLOG(WS_LOG_DEBUG, "Entering SendUserAuthKeyboardRequest()");
1337113377
1337213378
13373- if (ssh == NULL || authData == NULL) {
13374- ret = WS_BAD_ARGUMENT;
13379+ if (ssh == NULL || ssh->ctx == NULL|| authData == NULL) {
13380+ return WS_BAD_ARGUMENT;
1337513381 }
1337613382
13377- if (ssh->ctx->keyboardAuthCb == NULL) {
13378- WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
13379- ret = WS_BAD_USAGE;
13383+ if (ret == WS_SUCCESS){
13384+ if (ssh->ctx->keyboardAuthCb == NULL) {
13385+ WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
13386+ return WS_BAD_USAGE;
13387+ }
13388+ else {
13389+ ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13390+ ssh->keyboardAuthCtx);
13391+ }
1338013392 }
1338113393
1338213394 if (ret == WS_SUCCESS) {
13383- ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13384- ssh->keyboardAuthCtx);
13385- }
13386-
13387- if (authData->sf.keyboard.promptCount > 0 &&
13388- (authData->sf.keyboard.prompts == NULL ||
13389- authData->sf.keyboard.promptLengths == NULL ||
13390- authData->sf.keyboard.promptEcho == NULL)) {
13391-
13392- ret = WS_BAD_USAGE;
13395+ if (authData->sf.keyboard.promptCount > 0 &&
13396+ (authData->sf.keyboard.prompts == NULL ||
13397+ authData->sf.keyboard.promptLengths == NULL ||
13398+ authData->sf.keyboard.promptEcho == NULL)) {
13399+ ret = WS_BAD_USAGE;
13400+ }
1339313401 }
1339413402
13395- if (authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
13396- ret = WS_BAD_USAGE;
13403+ if (ret == WS_SUCCESS) {
13404+ if (authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
13405+ ret = WS_BAD_USAGE;
13406+ }
1339713407 }
1339813408
13399- ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
13409+ if (ret == WS_SUCCESS)
13410+ ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
1340013411
1340113412 payloadSz = MSG_ID_SZ;
1340213413 if (ret == WS_SUCCESS) {
@@ -13407,12 +13418,12 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1340713418 ret = PreparePacket(ssh, payloadSz);
1340813419 }
1340913420
13410- output = ssh->outputBuffer.buffer;
13411- idx = ssh->outputBuffer.length;
13421+ if (ret == WS_SUCCESS) {
13422+ output = ssh->outputBuffer.buffer;
13423+ idx = ssh->outputBuffer.length;
1341213424
13413- output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
13425+ output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
1341413426
13415- if (ret == WS_SUCCESS) {
1341613427 ret = BuildUserAuthRequestKeyboard(ssh, output, &idx, authData);
1341713428 }
1341813429
@@ -15117,7 +15128,7 @@ static int GetAllowedAuth(WOLFSSH* ssh, char* authStr)
1511715128
1511815129 typeAllowed |= WOLFSSH_USERAUTH_PASSWORD;
1511915130#ifdef WOLFSSH_KEYBOARD_INTERACTIVE
15120- if (ssh->ctx-> keyboardAuthCb != NULL ) {
15131+ if (ssh->ctx && ssh->ctx-> keyboardAuthCb) {
1512115132 typeAllowed |= WOLFSSH_USERAUTH_KEYBOARD;
1512215133 }
1512315134#endif
0 commit comments