Skip to content

Commit 2596d56

Browse files
committed
verify length limit for supported version ext
add length check to tls extensions
1 parent e32ac6f commit 2596d56

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/tls.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6972,8 +6972,10 @@ int TLSX_SupportedVersions_Parse(const WOLFSSL* ssl, const byte* input,
69726972
int set = 0;
69736973

69746974
/* Must contain a length and at least one version. */
6975-
if (length < OPAQUE8_LEN + OPAQUE16_LEN || (length & 1) != 1)
6975+
if (length < OPAQUE8_LEN + OPAQUE16_LEN || (length & 1) != 1
6976+
|| length > MAX_SV_EXT_LEN) {
69766977
return BUFFER_ERROR;
6978+
}
69776979

69786980
len = *input;
69796981

@@ -9963,10 +9965,13 @@ int TLSX_KeyShare_Parse_ClientHello(const WOLFSSL* ssl,
99639965
if (length < OPAQUE16_LEN)
99649966
return BUFFER_ERROR;
99659967

9966-
/* ClientHello contains zero or more key share entries. */
9968+
/* ClientHello contains zero or more key share entries. Limits extension
9969+
* length to 2^16-1 and subtracting 4 bytes for header size per RFC 8446 */
99679970
ato16(input, &len);
9968-
if (len != length - OPAQUE16_LEN)
9971+
if ((len != length - OPAQUE16_LEN) ||
9972+
length > (MAX_EXT_DATA_LEN - HELLO_EXT_SZ)) {
99699973
return BUFFER_ERROR;
9974+
}
99709975
offset += OPAQUE16_LEN;
99719976

99729977
while (offset < (int)length) {

wolfssl/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,12 @@ enum Misc {
16681668
MAX_REQUEST_SZ = 256, /* Maximum cert req len (no auth yet */
16691669
SESSION_FLUSH_COUNT = 256, /* Flush session cache unless user turns off */
16701670
TLS_MAX_PAD_SZ = 255, /* Max padding in TLS */
1671+
MAX_EXT_DATA_LEN = 65535,
1672+
/* Max extension data length <0..2^16-1> RFC 8446
1673+
* Section 4.2 */
1674+
MAX_SV_EXT_LEN = 255,
1675+
/* Max supported_versions extension length
1676+
* <2..254> RFC 8446 Section 4.2.1.*/
16711677

16721678
#if defined(HAVE_NULL_CIPHER) && defined(WOLFSSL_TLS13)
16731679
#if defined(WOLFSSL_SHA384) && WC_MAX_SYM_KEY_SIZE < 48

0 commit comments

Comments
 (0)