Skip to content

Commit 0cf031b

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 6ca048d commit 0cf031b

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)
@@ -15041,9 +15044,16 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1504115044
#endif
1504215045

1504315046
#if !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES)
15044-
case TLSX_CERTIFICATE_AUTHORITIES:
15045-
length += CAN_GET_SIZE(extension->data);
15047+
case TLSX_CERTIFICATE_AUTHORITIES: {
15048+
word16 canSz = CAN_GET_SIZE(extension->data);
15049+
/* 0 on non-empty list means 16-bit overflow. */
15050+
if (canSz == 0 && extension->data != NULL) {
15051+
ret = LENGTH_ERROR;
15052+
break;
15053+
}
15054+
length += canSz;
1504615055
break;
15056+
}
1504715057
#endif
1504815058
#endif
1504915059
#ifdef WOLFSSL_SRTP

0 commit comments

Comments
 (0)