Skip to content

Commit 8220c0a

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 64aa393 commit 8220c0a

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
@@ -7573,7 +7573,7 @@ static word16 TLSX_CA_Names_GetSize(void* data)
75737573
{
75747574
WOLFSSL* ssl = (WOLFSSL*)data;
75757575
WOLF_STACK_OF(WOLFSSL_X509_NAME)* names;
7576-
word16 size = 0;
7576+
word32 size = 0;
75777577

75787578
/* Length of names */
75797579
size += OPAQUE16_LEN;
@@ -7583,11 +7583,14 @@ static word16 TLSX_CA_Names_GetSize(void* data)
75837583

75847584
if (name != NULL) {
75857585
/* 16-bit length | SEQ | Len | DER of name */
7586-
size += (word16)(OPAQUE16_LEN + SetSequence(name->rawLen, seq) +
7586+
size += (word32)(OPAQUE16_LEN + SetSequence(name->rawLen, seq) +
75877587
name->rawLen);
7588+
if (size > WOLFSSL_MAX_16BIT) {
7589+
return 0;
7590+
}
75887591
}
75897592
}
7590-
return size;
7593+
return (word16)size;
75917594
}
75927595

75937596
static word16 TLSX_CA_Names_Write(void* data, byte* output)
@@ -14925,9 +14928,16 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1492514928
#endif
1492614929

1492714930
#if !defined(NO_CERTS) && !defined(WOLFSSL_NO_CA_NAMES)
14928-
case TLSX_CERTIFICATE_AUTHORITIES:
14929-
length += CAN_GET_SIZE(extension->data);
14931+
case TLSX_CERTIFICATE_AUTHORITIES: {
14932+
word16 canSz = CAN_GET_SIZE(extension->data);
14933+
/* 0 on non-empty list means 16-bit overflow. */
14934+
if (canSz == 0 && extension->data != NULL) {
14935+
ret = LENGTH_ERROR;
14936+
break;
14937+
}
14938+
length += canSz;
1493014939
break;
14940+
}
1493114941
#endif
1493214942
#endif
1493314943
#ifdef WOLFSSL_SRTP

0 commit comments

Comments
 (0)