Skip to content

Commit cc10e43

Browse files
committed
Sanitize input
1 parent 221f449 commit cc10e43

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/source/Crypto/Dtls_mbedtls.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ mbedtls_ssl_srtp_profile DTLS_SRTP_SUPPORTED_PROFILES[] = {
1010

1111
STATUS md5DigestCalculation(PBYTE inputStringBuff, UINT64 length, PBYTE outputBuff)
1212
{
13-
mbedtls_md5_ret(inputStringBuff, length, outputBuff);
14-
return STATUS_SUCCESS;
13+
STATUS retStatus = STATUS_SUCCESS;
14+
CHK_ERR(inputStringBuff != NULL && outputBuff != NULL, STATUS_INVALID_ARG, "Invalid input or output buffer");
15+
CHK_ERR(!mbedtls_md5_ret(inputStringBuff, length, outputBuff), STATUS_INTERNAL_ERROR, "MD5 calculation failed");
16+
CleanUp:
17+
return retStatus;
1518
}
19+
1620
STATUS createDtlsSession(PDtlsSessionCallbacks pDtlsSessionCallbacks, TIMER_QUEUE_HANDLE timerQueueHandle, INT32 certificateBits,
1721
BOOL generateRSACertificate, PRtcCertificate pRtcCertificates, PDtlsSession* ppDtlsSession)
1822
{

src/source/Crypto/Dtls_openssl.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ STATUS md5DigestCalculation(PBYTE inputStringBuff, UINT64 length, PBYTE outputBu
5050
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
5151
EVP_MD_CTX* mdctx = NULL;
5252
const EVP_MD* md = NULL;
53+
#endif
54+
55+
CHK_ERR(inputStringBuff != NULL && outputBuff != NULL, STATUS_INVALID_ARG, "Invalid input or output buffer");
56+
57+
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
58+
5359
CHK_ERR(md = EVP_MD_fetch(NULL, "MD5", NULL), STATUS_INTERNAL_ERROR, "Failed to fetch MD5 provider");
5460
mdctx = EVP_MD_CTX_new();
5561
CHK_ERR(EVP_DigestInit_ex(mdctx, md, NULL), STATUS_INTERNAL_ERROR, "Message digest initialization failed.");
@@ -61,11 +67,12 @@ STATUS md5DigestCalculation(PBYTE inputStringBuff, UINT64 length, PBYTE outputBu
6167

6268
CleanUp:
6369
#if (OPENSSL_VERSION_NUMBER >= 0x30000000L)
64-
EVP_MD_CTX_free(mdctx);
65-
EVP_MD_free((EVP_MD*) md);
66-
// Adding else to get around Mac unused label error
67-
#else
68-
retStatus = STATUS_SUCCESS;
70+
if (mdctx != NULL) {
71+
EVP_MD_CTX_free(mdctx);
72+
}
73+
if (md != NULL) {
74+
EVP_MD_free((EVP_MD*) md);
75+
}
6976
#endif
7077
return retStatus;
7178
}

0 commit comments

Comments
 (0)