The _nx_secure_tls_process_clienthello_psk_extension() function parses a list of id's. It checks to make sure there is enough data to read the list length, and if so, extracts the list length. It then uses the list length to drive a loop. Prior to the loop, there is code to check if the extracted list length is within bounds. This bounds check looks as follows:
if(list_length > extension_length)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
This look ok on first sight, however, there is an offset field that indicated where to read the next bytes from. At the time of of this check, the offset is 2. That bounds check does not account for the offset, and, hence, can allow for an off-by-two out of bound read.
code:
threadx\netxduo-master\nx_secure\src\nx_secure_tls_process_clienthello_extensions.c
static UINT _nx_secure_tls_process_clienthello_psk_extension(NX_SECURE_TLS_SESSION *tls_session, const UCHAR *packet_buffer,
USHORT extension_length, const UCHAR *client_hello_buffer, UINT client_hello_length)
{
UINT list_length;
...
if (extension_length < 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
/* Get the length of the ID list. (Extension id and length already removed by caller). */
list_length = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
offset += 2;
/* Make sure the length is reasonable. */
if(list_length > extension_length) // <-- this bounds check does not account for offset!
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
...
while(list_length > 0)
{
if (list_length < 2)
{
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
/* Extract ID length. */
id_len = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]); // <-- could read out of bound by 2 bytes
offset += 2;
...
}
...
}
The _nx_secure_tls_process_clienthello_psk_extension() function parses a list of id's. It checks to make sure there is enough data to read the list length, and if so, extracts the list length. It then uses the list length to drive a loop. Prior to the loop, there is code to check if the extracted list length is within bounds. This bounds check looks as follows:
This look ok on first sight, however, there is an offset field that indicated where to read the next bytes from. At the time of of this check, the offset is 2. That bounds check does not account for the offset, and, hence, can allow for an off-by-two out of bound read.
code:
threadx\netxduo-master\nx_secure\src\nx_secure_tls_process_clienthello_extensions.c