Skip to content

Commit 335c054

Browse files
committed
Fix SRTP KDF null-idx crash and X509 DER length hardening
- wolfcrypt/src/kdf.c: Add null idx guard to wc_SRTP_KDF, wc_SRTCP_KDF, wc_SRTP_KDF_kdr_to_idx, and wc_KDF_SRTP_label - src/x509.c: Add derCert->length > INT_MAX check in wolfSSL_X509_get_der and derSz <= 0 check in wolfSSL_i2d_X509
1 parent c36beba commit 335c054

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/x509.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4404,6 +4404,10 @@ const byte* wolfSSL_X509_get_der(WOLFSSL_X509* x509, int* outSz)
44044404
if (x509 == NULL || x509->derCert == NULL || outSz == NULL)
44054405
return NULL;
44064406

4407+
if (x509->derCert->length > (word32)INT_MAX) {
4408+
return NULL;
4409+
}
4410+
44074411
*outSz = (int)x509->derCert->length;
44084412
return x509->derCert->buffer;
44094413
}
@@ -8674,7 +8678,7 @@ int wolfSSL_i2d_X509(WOLFSSL_X509* x509, unsigned char** out)
86748678
}
86758679

86768680
der = wolfSSL_X509_get_der(x509, &derSz);
8677-
if (der == NULL) {
8681+
if (der == NULL || derSz <= 0) {
86788682
WOLFSSL_LEAVE("wolfSSL_i2d_X509", MEMORY_E);
86798683
return MEMORY_E;
86808684
}

wolfcrypt/src/kdf.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,8 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
10091009

10101010
/* Validate parameters. */
10111011
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
1012-
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24)) {
1012+
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24) ||
1013+
(idx == NULL && kdrIdx >= 0)) {
10131014
ret = BAD_FUNC_ARG;
10141015
}
10151016

@@ -1103,7 +1104,8 @@ int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt, word32 salt
11031104

11041105
/* Validate parameters. */
11051106
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
1106-
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24)) {
1107+
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24) ||
1108+
(idx == NULL && kdrIdx >= 0)) {
11071109
ret = BAD_FUNC_ARG;
11081110
}
11091111

@@ -1194,7 +1196,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
11941196
/* Validate parameters. */
11951197
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
11961198
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24) ||
1197-
(outKey == NULL)) {
1199+
(outKey == NULL) || (idx == NULL && kdrIdx >= 0)) {
11981200
ret = BAD_FUNC_ARG;
11991201
}
12001202

@@ -1267,7 +1269,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
12671269
/* Validate parameters. */
12681270
if ((key == NULL) || (keySz > AES_256_KEY_SIZE) || (salt == NULL) ||
12691271
(saltSz > WC_SRTP_MAX_SALT) || (kdrIdx < -1) || (kdrIdx > 24) ||
1270-
(outKey == NULL)) {
1272+
(outKey == NULL) || (idx == NULL && kdrIdx >= 0)) {
12711273
ret = BAD_FUNC_ARG;
12721274
}
12731275

0 commit comments

Comments
 (0)