Skip to content

Commit a133043

Browse files
Merge pull request #352 from ejohnstown/fix-fuzz
Fuzzing Fixes
2 parents 784567e + 064cfce commit a133043

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/internal.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,13 +3533,17 @@ static int DoKexDhGexGroup(WOLFSSH* ssh,
35333533
ret = GetMpint(&generatorSz, &generator, buf, len, &begin);
35343534

35353535
if (ret == WS_SUCCESS) {
3536+
if (ssh->handshake->primeGroup)
3537+
WFREE(ssh->handshake->primeGroup, ssh->ctx->heap, DYNTYPE_MPINT);
35363538
ssh->handshake->primeGroup =
35373539
(byte*)WMALLOC(primeGroupSz, ssh->ctx->heap, DYNTYPE_MPINT);
35383540
if (ssh->handshake->primeGroup == NULL)
35393541
ret = WS_MEMORY_E;
35403542
}
35413543

35423544
if (ret == WS_SUCCESS) {
3545+
if (ssh->handshake->generator)
3546+
WFREE(ssh->handshake->generator, ssh->ctx->heap, DYNTYPE_MPINT);
35433547
ssh->handshake->generator =
35443548
(byte*)WMALLOC(generatorSz, ssh->ctx->heap, DYNTYPE_MPINT);
35453549
if (ssh->handshake->generator == NULL) {

src/misc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ STATIC INLINE void CreateMpint(byte* buf, word32* sz, byte* pad)
130130
WLOG(WS_LOG_ERROR, "Internal argument error with CreateMpint");
131131
}
132132

133+
if (*sz == 0)
134+
return;
135+
133136
/* check for leading 0's */
134137
for (i = 0; i < *sz; i++) {
135138
if (buf[i] != 0x00)

0 commit comments

Comments
 (0)