Skip to content

Commit 67de234

Browse files
committed
Add sanity checks in key export
1 parent 47033c4 commit 67de234

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/ssl.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5726,6 +5726,13 @@ int wolfSSL_export_keying_material(WOLFSSL *ssl,
57265726
return WOLFSSL_FAILURE;
57275727
}
57285728

5729+
/* Sanity check contextLen to prevent integer overflow when cast to word32
5730+
* and to ensure it fits in the 2-byte length encoding (max 65535). */
5731+
if (use_context && contextLen > UINT16_MAX) {
5732+
WOLFSSL_MSG("contextLen too large");
5733+
return WOLFSSL_FAILURE;
5734+
}
5735+
57295736
/* clientRandom + serverRandom
57305737
* OR
57315738
* clientRandom + serverRandom + ctx len encoding + ctx */

src/tls13.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,11 @@ int Tls13_Exporter(WOLFSSL* ssl, unsigned char *out, size_t outLen,
10231023
if (ret != 0)
10241024
return ret;
10251025

1026+
/* Sanity check contextLen to prevent truncation when cast to word32. */
1027+
if (contextLen > UINT32_MAX) {
1028+
return BAD_FUNC_ARG;
1029+
}
1030+
10261031
/* Hash(context_value) */
10271032
ret = wc_Hash(hashType, context, (word32)contextLen, hashOut, WC_MAX_DIGEST_SIZE);
10281033
if (ret != 0)

0 commit comments

Comments
 (0)