From 064cfce0d906e9ec2f4f16caf3e497c87df4d861 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Tue, 20 Jul 2021 16:23:15 -0700 Subject: [PATCH] Fuzzing Fixes 1. Fixed a leak. 2. Fixed a branch on uninitialized. (ZD 12640 and 12642) --- src/internal.c | 4 ++++ src/misc.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/internal.c b/src/internal.c index 7c3384cd6..5ac3ae3c6 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3533,6 +3533,8 @@ static int DoKexDhGexGroup(WOLFSSH* ssh, ret = GetMpint(&generatorSz, &generator, buf, len, &begin); if (ret == WS_SUCCESS) { + if (ssh->handshake->primeGroup) + WFREE(ssh->handshake->primeGroup, ssh->ctx->heap, DYNTYPE_MPINT); ssh->handshake->primeGroup = (byte*)WMALLOC(primeGroupSz, ssh->ctx->heap, DYNTYPE_MPINT); if (ssh->handshake->primeGroup == NULL) @@ -3540,6 +3542,8 @@ static int DoKexDhGexGroup(WOLFSSH* ssh, } if (ret == WS_SUCCESS) { + if (ssh->handshake->generator) + WFREE(ssh->handshake->generator, ssh->ctx->heap, DYNTYPE_MPINT); ssh->handshake->generator = (byte*)WMALLOC(generatorSz, ssh->ctx->heap, DYNTYPE_MPINT); if (ssh->handshake->generator == NULL) { diff --git a/src/misc.c b/src/misc.c index 95f00256b..aa86e328f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -130,6 +130,9 @@ STATIC INLINE void CreateMpint(byte* buf, word32* sz, byte* pad) WLOG(WS_LOG_ERROR, "Internal argument error with CreateMpint"); } + if (*sz == 0) + return; + /* check for leading 0's */ for (i = 0; i < *sz; i++) { if (buf[i] != 0x00)