Skip to content

Commit 7e9f1ae

Browse files
authored
Merge pull request #777 from JacobBarthelmeh/testing
sanity check and free temporary strings on failure
2 parents 697f54a + 97c3faf commit 7e9f1ae

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/internal.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7886,14 +7886,15 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
78867886
if (!prompts) {
78877887
ret = WS_MEMORY_E;
78887888
} else {
7889+
WMEMSET(prompts, '\0', sizeof(char*) * promptSz);
78897890
echo = (byte*)WMALLOC(sizeof(byte) * promptSz, ssh->ctx->heap,
78907891
DYNTYPE_BUFFER);
78917892
}
78927893

78937894
if (!echo) {
78947895
ret = WS_MEMORY_E;
78957896
} else {
7896-
WMEMSET(prompts, '\0', sizeof(char*) * promptSz);
7897+
WMEMSET(echo, 0, sizeof(byte) * promptSz);
78977898
for (entry = 0; entry < promptSz; entry++) {
78987899
ret = GetStringAlloc(ssh->ctx->heap, (char**)&prompts[entry],
78997900
buf, len, &begin);
@@ -7923,6 +7924,11 @@ static int DoUserAuthInfoRequest(WOLFSSH* ssh, byte* buf, word32 len,
79237924
}
79247925
WFREE(prompts, ssh->ctx->heap, DYNTYPE_BUFFER);
79257926
WFREE(echo, ssh->ctx->heap, DYNTYPE_BUFFER);
7927+
7928+
/* free strings in fail case */
7929+
WFREE(authName, ssh->ctx->heap, DYNTYPE_STRING);
7930+
WFREE(authInstruction, ssh->ctx->heap, DYNTYPE_STRING);
7931+
WFREE(language, ssh->ctx->heap, DYNTYPE_STRING);
79267932
}
79277933

79287934
if (ret == WS_SUCCESS)
@@ -10109,8 +10115,13 @@ static int BundlePacket(WOLFSSH* ssh)
1010910115

1011010116
/* Add the padding */
1011110117
WLOG(WS_LOG_DEBUG, "BP: paddingSz = %u", paddingSz);
10112-
if (ssh->encryptId == ID_NONE)
10118+
if (idx + paddingSz > ssh->outputBuffer.bufferSz) {
10119+
ret = WS_BUFFER_E;
10120+
WLOG(WS_LOG_DEBUG, "BP: paddingSz was too large");
10121+
}
10122+
else if (ssh->encryptId == ID_NONE) {
1011310123
WMEMSET(output + idx, 0, paddingSz);
10124+
}
1011410125
else if (wc_RNG_GenerateBlock(ssh->rng, output + idx, paddingSz) < 0) {
1011510126
ret = WS_CRYPTO_FAILED;
1011610127
WLOG(WS_LOG_DEBUG, "BP: failed to add padding");

0 commit comments

Comments
 (0)