Skip to content

Commit 88553f6

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 28dc5ab commit 88553f6

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/tls.c

Lines changed: 6 additions & 3 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)

0 commit comments

Comments
 (0)