Skip to content

Commit 2396169

Browse files
committed
tests: cover input validation fixes
1 parent 818912e commit 2396169

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

tests/api.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12119,6 +12119,19 @@ static int test_wc_PemToDer(void)
1211912119
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
1212012120
}
1212112121
#endif
12122+
/* NULL buff, zero size, and negative size must be rejected up front. The
12123+
* pre-fix code cast longSz to word32, so a negative value drove an
12124+
* over-read inside PemToDer. */
12125+
{
12126+
const byte stub[] = "x";
12127+
DerBuffer* badDer = NULL;
12128+
ExpectIntEQ(wc_PemToDer(NULL, 100, CERT_TYPE, &badDer, NULL, &info,
12129+
&eccKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
12130+
ExpectIntEQ(wc_PemToDer(stub, 0, CERT_TYPE, &badDer, NULL, &info,
12131+
&eccKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
12132+
ExpectIntEQ(wc_PemToDer(stub, -1, CERT_TYPE, &badDer, NULL, &info,
12133+
&eccKey), WC_NO_ERR_TRACE(BAD_FUNC_ARG));
12134+
}
1212212135
#endif
1212312136
return EXPECT_RESULT();
1212412137
}

tests/api/test_pkcs7.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,6 +5028,14 @@ int test_wc_PKCS7_DecodeCompressedData(void)
50285028
ExpectNotNull(decompressed);
50295029
ExpectIntEQ(XMEMCMP(decompressed, cert_buf, cert_sz), 0);
50305030
XFREE(decompressed, heap, DYNAMIC_TYPE_TMP_BUFFER);
5031+
decompressed = NULL;
5032+
5033+
/* inSz that would overflow on the initial 'tmpSz = inSz * 2' must be
5034+
* rejected up front rather than handed to XMALLOC. */
5035+
ExpectIntEQ(wc_DeCompressDynamic(&decompressed, -1, DYNAMIC_TYPE_TMP_BUFFER,
5036+
out, ((word32)INT_MAX / 2) + 1, 0, heap),
5037+
WC_NO_ERR_TRACE(BAD_FUNC_ARG));
5038+
ExpectNull(decompressed);
50315039

50325040
if (cert_buf != NULL)
50335041
XFREE(cert_buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);

0 commit comments

Comments
 (0)