Skip to content

Commit 8cff8a5

Browse files
committed
Fix wolfSSH client: freeing uninitialized data
1 parent 8d0c8a5 commit 8cff8a5

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/internal.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,6 +3553,7 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
35533553
int ret = WS_SUCCESS;
35543554
int tmpIdx = 0;
35553555
struct wolfSSH_sigKeyBlock *sigKeyBlock_ptr = NULL;
3556+
byte keyAllocated = 0;
35563557
#ifndef WOLFSSH_NO_ECDH
35573558
ecc_key *key_ptr = NULL;
35583559
#ifndef WOLFSSH_SMALL_STACK
@@ -3780,7 +3781,9 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
37803781

37813782
ret = ParsePubKey(ssh, sigKeyBlock_ptr, pubKey, pubKeySz);
37823783
/* Generate and hash in the shared secret */
3783-
if (ret == WS_SUCCESS) {
3784+
if (ret == WS_SUCCESS) {
3785+
/* Remember that the key needs to be freed */
3786+
keyAllocated = 1;
37843787
/* reset size here because a previous shared secret could
37853788
* potentially be smaller by a byte than usual and cause buffer
37863789
* issues with re-key */
@@ -4025,15 +4028,17 @@ static int DoKexDhReply(WOLFSSH* ssh, byte* buf, word32 len, word32* idx)
40254028
}
40264029
}
40274030

4028-
if (sigKeyBlock_ptr->useRsa) {
4031+
if (keyAllocated) {
4032+
if (sigKeyBlock_ptr->useRsa) {
40294033
#ifndef WOLFSSH_NO_RSA
4030-
wc_FreeRsaKey(&sigKeyBlock_ptr->sk.rsa.key);
4034+
wc_FreeRsaKey(&sigKeyBlock_ptr->sk.rsa.key);
40314035
#endif
4032-
}
4033-
else {
4036+
}
4037+
else {
40344038
#ifndef WOLFSSH_NO_ECDSA
4035-
wc_ecc_free(&sigKeyBlock_ptr->sk.ecc.key);
4039+
wc_ecc_free(&sigKeyBlock_ptr->sk.ecc.key);
40364040
#endif
4041+
}
40374042
}
40384043
}
40394044

0 commit comments

Comments
 (0)