Skip to content

Commit 79b66e9

Browse files
committed
Fix a minor memory leak in kex.c.
We need to ensure that cc20-mt and cc20-serial are in the kex proposal string. However, the prior method created a small memory leak. This patch resolves that leak. Passes regression and fuzz testing.
1 parent 6112792 commit 79b66e9

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

kex.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,11 @@ patch_list(char * orig)
10411041
int
10421042
kex_ready(struct ssh *ssh, char *proposal[PROPOSAL_MAX])
10431043
{
1044-
int r;
1044+
int r = 0;
10451045

10461046
#ifdef WITH_OPENSSL
1047+
char * orig_ctos = proposal[PROPOSAL_ENC_ALGS_CTOS];
1048+
char * orig_stoc = proposal[PROPOSAL_ENC_ALGS_STOC];
10471049
proposal[PROPOSAL_ENC_ALGS_CTOS] =
10481050
patch_list(proposal[PROPOSAL_ENC_ALGS_CTOS]);
10491051
proposal[PROPOSAL_ENC_ALGS_STOC] =
@@ -1057,11 +1059,18 @@ kex_ready(struct ssh *ssh, char *proposal[PROPOSAL_MAX])
10571059
#endif
10581060

10591061
if ((r = kex_prop2buf(ssh->kex->my, proposal)) != 0)
1060-
return r;
1062+
goto restoreProposal;
10611063
ssh->kex->flags = KEX_INITIAL;
10621064
kex_reset_dispatch(ssh);
10631065
ssh_dispatch_set(ssh, SSH2_MSG_KEXINIT, &kex_input_kexinit);
1064-
return 0;
1066+
restoreProposal:
1067+
#ifdef WITH_OPENSSL
1068+
free(proposal[PROPOSAL_ENC_ALGS_CTOS]);
1069+
free(proposal[PROPOSAL_ENC_ALGS_STOC]);
1070+
proposal[PROPOSAL_ENC_ALGS_CTOS] = orig_ctos;
1071+
proposal[PROPOSAL_ENC_ALGS_STOC] = orig_stoc;
1072+
#endif
1073+
return r;
10651074
}
10661075

10671076
int

0 commit comments

Comments
 (0)