Skip to content

Commit

Permalink
improve malformed length tests
Browse files Browse the repository at this point in the history
  • Loading branch information
goatgoose committed Sep 19, 2023
1 parent 8ed2600 commit fd16f15
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tests/unit/s2n_client_hello_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,8 @@ int main(int argc, char **argv)

/* s2n_client_hello_get_supported_groups tests */
{

/* Allocate space for 2 length bytes and S2N_MAX_RECEIVED_SUPPORTED_GROUPS groups */
#define TEST_SUPPORTED_GROUPS_EXTENSION_SIZE (2 + (S2N_MAX_RECEIVED_SUPPORTED_GROUPS * 2))

/* Safety */
{
Expand Down Expand Up @@ -1692,6 +1693,8 @@ int main(int argc, char **argv)

/* Test s2n_client_hello_get_supported_groups when a supported groups extension wasn't received. */
{
struct s2n_client_hello client_hello = { 0 };


}

Expand All @@ -1702,17 +1705,16 @@ int main(int argc, char **argv)
s2n_extension_type_id supported_groups_id = 0;
EXPECT_SUCCESS(s2n_extension_supported_iana_value_to_id(S2N_EXTENSION_SUPPORTED_GROUPS, &supported_groups_id));

/* Allocate space for 2 length bytes and S2N_MAX_RECEIVED_SUPPORTED_GROUPS groups */
uint8_t extension_data[2 + (S2N_MAX_RECEIVED_SUPPORTED_GROUPS * 2)] = { 0 };
struct s2n_blob extension_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&extension_blob, extension_data, sizeof(extension_data)));

s2n_parsed_extension *supported_groups_extension = &client_hello.extensions.parsed_extensions[supported_groups_id];
supported_groups_extension->extension = extension_blob;
supported_groups_extension->extension_type = S2N_EXTENSION_SUPPORTED_GROUPS;

/* Test parsing a correct groups list length */
{
uint8_t extension_data[TEST_SUPPORTED_GROUPS_EXTENSION_SIZE] = { 0 };
struct s2n_blob extension_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&extension_blob, extension_data, sizeof(extension_data)));
supported_groups_extension->extension = extension_blob;

struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

Expand All @@ -1729,6 +1731,11 @@ int main(int argc, char **argv)

/* Test parsing a groups list length that is larger than the extension length */
{
uint8_t extension_data[TEST_SUPPORTED_GROUPS_EXTENSION_SIZE] = { 0 };
struct s2n_blob extension_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&extension_blob, extension_data, sizeof(extension_data)));
supported_groups_extension->extension = extension_blob;

struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

Expand All @@ -1746,6 +1753,11 @@ int main(int argc, char **argv)

/* Test parsing a groups list that contains a partial supported group */
{
uint8_t extension_data[TEST_SUPPORTED_GROUPS_EXTENSION_SIZE] = { 0 };
struct s2n_blob extension_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&extension_blob, extension_data, sizeof(extension_data)));
supported_groups_extension->extension = extension_blob;

struct s2n_stuffer extension_stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_init(&extension_stuffer, &extension_blob));

Expand All @@ -1760,7 +1772,6 @@ int main(int argc, char **argv)

EXPECT_EQUAL(supported_groups_count, 0);
}

}

/* Ensure that s2n_client_hello_get_supported_groups writes what is contained in the parsed
Expand Down

0 comments on commit fd16f15

Please sign in to comment.