Skip to content

Commit caa6a0e

Browse files
committed
tls: fix TLSX_CA_Names_GetSize word16 overflow (F-2927)
The CA Names extension size accumulator was a word16. With enough CA entries (or large DER-encoded names) the running total can wrap silently, leaving TLSX_CA_Names_Write to overflow an undersized extension buffer. Match TLSX_SNI_GetSize: use a word32 accumulator and return 0 when the total exceeds WOLFSSL_MAX_16BIT.
1 parent c7d5eba commit caa6a0e

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/tls.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7576,7 +7576,7 @@ static word16 TLSX_CA_Names_GetSize(void* data)
75767576
{
75777577
WOLFSSL* ssl = (WOLFSSL*)data;
75787578
WOLF_STACK_OF(WOLFSSL_X509_NAME)* names;
7579-
word16 size = 0;
7579+
word32 size = 0;
75807580

75817581
/* Length of names */
75827582
size += OPAQUE16_LEN;
@@ -7586,11 +7586,14 @@ static word16 TLSX_CA_Names_GetSize(void* data)
75867586

75877587
if (name != NULL) {
75887588
/* 16-bit length | SEQ | Len | DER of name */
7589-
size += (word16)(OPAQUE16_LEN + SetSequence(name->rawLen, seq) +
7589+
size += (word32)(OPAQUE16_LEN + SetSequence(name->rawLen, seq) +
75907590
name->rawLen);
7591+
if (size > WOLFSSL_MAX_16BIT) {
7592+
return 0;
7593+
}
75917594
}
75927595
}
7593-
return size;
7596+
return (word16)size;
75947597
}
75957598

75967599
static word16 TLSX_CA_Names_Write(void* data, byte* output)
@@ -14927,9 +14930,16 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1492714930
#endif
1492814931

1492914932
#if !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES)
14930-
case TLSX_CERTIFICATE_AUTHORITIES:
14931-
length += CAN_GET_SIZE(extension->data);
14933+
case TLSX_CERTIFICATE_AUTHORITIES: {
14934+
word16 canSz = CAN_GET_SIZE(extension->data);
14935+
/* 0 on non-empty list means 16-bit overflow. */
14936+
if (canSz == 0 && extension->data != NULL) {
14937+
ret = LENGTH_ERROR;
14938+
break;
14939+
}
14940+
length += canSz;
1493214941
break;
14942+
}
1493314943
#endif
1493414944
#endif
1493514945
#ifdef WOLFSSL_SRTP

0 commit comments

Comments
 (0)