Skip to content

Commit 246cc90

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 c92861e commit 246cc90

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
@@ -2945,7 +2945,7 @@ static void TLSX_TCA_FreeAll(TCA* list, void* heap)
29452945
static word16 TLSX_TCA_GetSize(TCA* list)
29462946
{
29472947
TCA* tca;
2948-
word16 length = OPAQUE16_LEN; /* list length */
2948+
word32 length = OPAQUE16_LEN; /* list length */
29492949

29502950
while ((tca = list)) {
29512951
list = tca->next;
@@ -2963,9 +2963,13 @@ static word16 TLSX_TCA_GetSize(TCA* list)
29632963
length += OPAQUE16_LEN + tca->idSz;
29642964
break;
29652965
}
2966+
2967+
if (length > WOLFSSL_MAX_16BIT) {
2968+
return 0;
2969+
}
29662970
}
29672971

2968-
return length;
2972+
return (word16)length;
29692973
}
29702974

29712975
/** Writes the TCA objects of a list in a buffer. */
@@ -14888,8 +14892,15 @@ static int TLSX_GetSize(TLSX* list, byte* semaphore, byte msgType,
1488814892

1488914893
case TLSX_TRUSTED_CA_KEYS:
1489014894
/* TCA only sends the list on the request. */
14891-
if (isRequest)
14892-
length += TCA_GET_SIZE((TCA*)extension->data);
14895+
if (isRequest) {
14896+
word16 tcaSz = TCA_GET_SIZE((TCA*)extension->data);
14897+
/* 0 on non-empty list means 16-bit overflow. */
14898+
if (tcaSz == 0 && extension->data != NULL) {
14899+
ret = LENGTH_ERROR;
14900+
break;
14901+
}
14902+
length += tcaSz;
14903+
}
1489314904
break;
1489414905

1489514906
case TLSX_MAX_FRAGMENT_LENGTH:

0 commit comments

Comments
 (0)