The _nx_secure_tls_proc_clienthello_supported_versions_extension() function parses out version extensions from a TLS packet. The extension format for this starts with a 1 byte length field, followed by 2 byte versions.
The code make sure there is at least 1 byte to read (the length field) and make sure the length field is equal to the extension length field (minus 1, since that also includes the length field itself).
If that matches, a for loop is entered. The for loop is bounded by the extension_length field. Inside the for loop it will then extract a 2 byte version. The first byte is guaranteed to be within bounds, the second byte could be out of bound if the length of the content is odd.
code:
threadx\netxduo-master\nx_secure\src\nx_secure_tls_process_clienthello_extensions.c
static UINT _nx_secure_tls_proc_clienthello_supported_versions_extension(NX_SECURE_TLS_SESSION *tls_session,
UCHAR *packet_buffer,
USHORT *supported_version,
USHORT extension_length)
{
UINT i;
ULONG offset;
...
offset = 0;
...
if ((extension_length) < 1 || (packet_buffer[0] != (extension_length - 1)))
{
/* Invalid Supported Versions Length. */
return(NX_SECURE_TLS_INCORRECT_MESSAGE_LENGTH);
}
offset = 1;
...
for (i = 0; i < (UINT)(extension_length - 1); i += 2)
{
/* Find the preferred protocol version. */
*supported_version = (USHORT)((packet_buffer[offset] << 8) + packet_buffer[offset + 1]);
...
}
...
}
The _nx_secure_tls_proc_clienthello_supported_versions_extension() function parses out version extensions from a TLS packet. The extension format for this starts with a 1 byte length field, followed by 2 byte versions.
The code make sure there is at least 1 byte to read (the length field) and make sure the length field is equal to the extension length field (minus 1, since that also includes the length field itself).
If that matches, a for loop is entered. The for loop is bounded by the extension_length field. Inside the for loop it will then extract a 2 byte version. The first byte is guaranteed to be within bounds, the second byte could be out of bound if the length of the content is odd.
code:
threadx\netxduo-master\nx_secure\src\nx_secure_tls_process_clienthello_extensions.c