Skip to content

Commit 15495ab

Browse files
committed
add ret checks for WS_SUCCESS to prevent dereference after null check
NULL check before dereferencing authData additional checks
1 parent 13a1c4a commit 15495ab

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/internal.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13377,7 +13377,7 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1337713377
ret = WS_BAD_ARGUMENT;
1337813378
}
1337913379

13380-
if (ssh->ctx->keyboardAuthCb == NULL) {
13380+
if (ssh->ctx && ssh->ctx->keyboardAuthCb == NULL) {
1338113381
WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
1338213382
ret = WS_BAD_USAGE;
1338313383
}
@@ -13387,19 +13387,21 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1338713387
ssh->keyboardAuthCtx);
1338813388
}
1338913389

13390-
if (authData->sf.keyboard.promptCount > 0 &&
13390+
if ((ret == WS_SUCCESS) && authData->sf.keyboard.promptCount > 0 &&
1339113391
(authData->sf.keyboard.prompts == NULL ||
1339213392
authData->sf.keyboard.promptLengths == NULL ||
1339313393
authData->sf.keyboard.promptEcho == NULL)) {
1339413394

1339513395
ret = WS_BAD_USAGE;
1339613396
}
1339713397

13398-
if (authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
13398+
if ((ret == WS_SUCCESS) &&
13399+
authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
1339913400
ret = WS_BAD_USAGE;
1340013401
}
1340113402

13402-
ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
13403+
if (ret == WS_SUCCESS)
13404+
ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
1340313405

1340413406
payloadSz = MSG_ID_SZ;
1340513407
if (ret == WS_SUCCESS) {
@@ -13410,12 +13412,12 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1341013412
ret = PreparePacket(ssh, payloadSz);
1341113413
}
1341213414

13413-
output = ssh->outputBuffer.buffer;
13414-
idx = ssh->outputBuffer.length;
13415+
if (ret == WS_SUCCESS) {
13416+
output = ssh->outputBuffer.buffer;
13417+
idx = ssh->outputBuffer.length;
1341513418

13416-
output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
13419+
output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
1341713420

13418-
if (ret == WS_SUCCESS) {
1341913421
ret = BuildUserAuthRequestKeyboard(ssh, output, &idx, authData);
1342013422
}
1342113423

0 commit comments

Comments
 (0)