Skip to content

Commit ed686d9

Browse files
committed
tls: fix TLSX_TCA_GetSize word16 overflow (F-2131)
Mirror the TLSX_SNI_GetSize pattern: accumulate into a word32 and return 0 when the aggregate size exceeds WOLFSSL_MAX_16BIT so large idSz values or many TCA entries no longer silently wrap to a small value that undersizes the TLSX_TCA_Write output buffer.
1 parent 51817a9 commit ed686d9

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/tls.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2942,7 +2942,7 @@ static void TLSX_TCA_FreeAll(TCA* list, void* heap)
29422942
static word16 TLSX_TCA_GetSize(TCA* list)
29432943
{
29442944
TCA* tca;
2945-
word16 length = OPAQUE16_LEN; /* list length */
2945+
word32 length = OPAQUE16_LEN; /* list length */
29462946

29472947
while ((tca = list)) {
29482948
list = tca->next;
@@ -2960,9 +2960,13 @@ static word16 TLSX_TCA_GetSize(TCA* list)
29602960
length += OPAQUE16_LEN + tca->idSz;
29612961
break;
29622962
}
2963+
2964+
if (length > WOLFSSL_MAX_16BIT) {
2965+
return 0;
2966+
}
29632967
}
29642968

2965-
return length;
2969+
return (word16)length;
29662970
}
29672971

29682972
/** Writes the TCA objects of a list in a buffer. */
@@ -14798,8 +14802,15 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1479814802

1479914803
case TLSX_TRUSTED_CA_KEYS:
1480014804
/* TCA only sends the list on the request. */
14801-
if (isRequest)
14802-
length += TCA_GET_SIZE((TCA*)extension->data);
14805+
if (isRequest) {
14806+
word16 tcaSz = TCA_GET_SIZE((TCA*)extension->data);
14807+
/* 0 on non-empty list means 16-bit overflow. */
14808+
if (tcaSz == 0 && extension->data != NULL) {
14809+
ret = LENGTH_ERROR;
14810+
break;
14811+
}
14812+
length += tcaSz;
14813+
}
1480314814
break;
1480414815

1480514816
case TLSX_MAX_FRAGMENT_LENGTH:

0 commit comments

Comments
 (0)