Skip to content

Commit 4796e34

Browse files
committed
add ret checks for WS_SUCCESS to prevent dereference after null check
NULL check before dereferencing authData additional checks formatting changes adjust return values
1 parent 13a1c4a commit 4796e34

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

src/internal.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13321,7 +13321,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1332113321
begin += LENGTH_SZ;
1332213322
WMEMCPY(output + begin, authData->sf.keyboard.promptName, slen);
1332313323
begin += slen;
13324-
} else {
13324+
}
13325+
else {
1332513326
c32toa(0, output + begin);
1332613327
begin += LENGTH_SZ;
1332713328
}
@@ -13331,7 +13332,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1333113332
begin += LENGTH_SZ;
1333213333
WMEMCPY(output + begin, authData->sf.keyboard.promptInstruction, slen);
1333313334
begin += slen;
13334-
} else {
13335+
}
13336+
else {
1333513337
c32toa(0, output + begin);
1333613338
begin += LENGTH_SZ;
1333713339
}
@@ -13341,7 +13343,8 @@ static int BuildUserAuthRequestKeyboard(WOLFSSH* ssh, byte* output, word32* idx,
1334113343
begin += LENGTH_SZ;
1334213344
WMEMCPY(output + begin, authData->sf.keyboard.promptLanguage, slen);
1334313345
begin += slen;
13344-
} else {
13346+
}
13347+
else {
1334513348
c32toa(0, output + begin);
1334613349
begin += LENGTH_SZ;
1334713350
}
@@ -13373,33 +13376,38 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1337313376
WLOG(WS_LOG_DEBUG, "Entering SendUserAuthKeyboardRequest()");
1337413377

1337513378

13376-
if (ssh == NULL || authData == NULL) {
13377-
ret = WS_BAD_ARGUMENT;
13379+
if (ssh == NULL || ssh->ctx == NULL|| authData == NULL) {
13380+
return WS_BAD_ARGUMENT;
1337813381
}
1337913382

13380-
if (ssh->ctx->keyboardAuthCb == NULL) {
13381-
WLOG(WS_LOG_DEBUG, "SendUserAuthKeyboardRequest called with no Cb set");
13382-
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+
}
1338313392
}
1338413393

1338513394
if (ret == WS_SUCCESS) {
13386-
ret = ssh->ctx->keyboardAuthCb(&authData->sf.keyboard,
13387-
ssh->keyboardAuthCtx);
13388-
}
13389-
13390-
if (authData->sf.keyboard.promptCount > 0 &&
13391-
(authData->sf.keyboard.prompts == NULL ||
13392-
authData->sf.keyboard.promptLengths == NULL ||
13393-
authData->sf.keyboard.promptEcho == NULL)) {
13394-
13395-
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+
}
1339613401
}
1339713402

13398-
if (authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
13399-
ret = WS_BAD_USAGE;
13403+
if (ret == WS_SUCCESS) {
13404+
if (authData->sf.keyboard.promptCount > WOLFSSH_MAX_PROMPTS) {
13405+
ret = WS_BAD_USAGE;
13406+
}
1340013407
}
1340113408

13402-
ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
13409+
if (ret == WS_SUCCESS)
13410+
ssh->kbAuth.promptCount = authData->sf.keyboard.promptCount;
1340313411

1340413412
payloadSz = MSG_ID_SZ;
1340513413
if (ret == WS_SUCCESS) {
@@ -13410,12 +13418,12 @@ int SendUserAuthKeyboardRequest(WOLFSSH* ssh, WS_UserAuthData* authData)
1341013418
ret = PreparePacket(ssh, payloadSz);
1341113419
}
1341213420

13413-
output = ssh->outputBuffer.buffer;
13414-
idx = ssh->outputBuffer.length;
13421+
if (ret == WS_SUCCESS) {
13422+
output = ssh->outputBuffer.buffer;
13423+
idx = ssh->outputBuffer.length;
1341513424

13416-
output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
13425+
output[idx++] = MSGID_USERAUTH_INFO_REQUEST;
1341713426

13418-
if (ret == WS_SUCCESS) {
1341913427
ret = BuildUserAuthRequestKeyboard(ssh, output, &idx, authData);
1342013428
}
1342113429

0 commit comments

Comments
 (0)