Skip to content

Commit

Permalink
Initialize blobs and stuffers (#3783)
Browse files Browse the repository at this point in the history
  • Loading branch information
lrstewart authored Jan 27, 2023
1 parent 7c395a0 commit 4aec93c
Show file tree
Hide file tree
Showing 68 changed files with 228 additions and 228 deletions.
2 changes: 1 addition & 1 deletion tests/testlib/s2n_testlib_ecc_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int s2n_public_ecc_keys_are_equal(struct s2n_ecc_evp_params *params_1, struct s2
POSIX_ENSURE_REF(params_1);
POSIX_ENSURE_REF(params_2);

struct s2n_stuffer point_stuffer;
struct s2n_stuffer point_stuffer = { 0 };
int size = params_1->negotiated_curve->share_size;

if (params_1->negotiated_curve != params_2->negotiated_curve) {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_blob_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(int argc, char **argv)
EXPECT_FAILURE(s2n_free(NULL));

/* Static blob is not growable or freeable */
struct s2n_blob g1;
struct s2n_blob g1 = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&g1, array, 12));
EXPECT_FALSE(s2n_blob_is_growable(&g1));
EXPECT_FAILURE(s2n_realloc(&g1, 24));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_cert_status_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_cert_status_extension.send(conn, &stuffer));
Expand Down Expand Up @@ -113,7 +113,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_cert_status_extension.send(conn, &stuffer));
Expand All @@ -134,7 +134,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_test_enable_sending_extension(conn));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_stuffer_write_uint8(&stuffer, S2N_STATUS_REQUEST_NONE));
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/s2n_client_alpn_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_protocol_preferences(conn, protocols, protocols_count));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_alpn_extension.send(conn, &stuffer));
Expand All @@ -70,7 +70,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_protocol_preferences(conn, protocols, protocols_count));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_alpn_extension.send(conn, &stuffer));
Expand All @@ -89,7 +89,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_alpn_extension.send(conn, &stuffer));
Expand All @@ -107,7 +107,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_alpn_extension.send(conn, &stuffer));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/s2n_client_auth_handshake_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ int s2n_test_client_auth_message_by_message(bool no_cert)
server_conn->x509_validator.skip_cert_validation = 1;
}

struct s2n_stuffer client_to_server;
struct s2n_stuffer server_to_client;
struct s2n_stuffer client_to_server = { 0 };
struct s2n_stuffer server_to_client = { 0 };

EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&client_to_server, 0));
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&server_to_client, 0));
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/s2n_client_cert_status_request_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_cert_status_request_extension.send(conn, &stuffer));
Expand All @@ -75,7 +75,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_cert_status_request_extension.send(conn, &stuffer));
Expand All @@ -94,7 +94,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_cert_status_request_extension.send(conn, &stuffer));
Expand All @@ -118,7 +118,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, bad_config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_cert_status_request_extension.send(conn, &stuffer));
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/s2n_client_empty_cert_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int main(int argc, char **argv)

/* Test s2n_send_empty_cert_chain */
{
struct s2n_stuffer out;
struct s2n_stuffer out = { 0 };
/* Magic number 3 is the length of the certificate_length field */
EXPECT_SUCCESS(s2n_stuffer_alloc(&out, 3));

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/s2n_client_hello_retry_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ int main(int argc, char **argv)
POSIX_GUARD_RESULT(s2n_handshake_copy_hash_state(server_conn, server_keys.hash_algorithm, &server_hash));
POSIX_GUARD(s2n_hash_digest(&server_hash, server_digest_out, hash_digest_length));

struct s2n_blob server_blob;
struct s2n_blob server_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&server_blob, server_digest_out, hash_digest_length));

EXPECT_SUCCESS(s2n_stuffer_wipe(&client_conn->handshake.io));
Expand All @@ -394,7 +394,7 @@ int main(int argc, char **argv)
POSIX_GUARD_RESULT(s2n_handshake_copy_hash_state(client_conn, client_keys.hash_algorithm, &client_hash));
POSIX_GUARD(s2n_hash_digest(&client_hash, client_digest_out, hash_digest_length));

struct s2n_blob client_blob;
struct s2n_blob client_blob = { 0 };
EXPECT_SUCCESS(s2n_blob_init(&client_blob, client_digest_out, hash_digest_length));

/* Test that the transcript hash recreated MUST be the same on the server and client side */
Expand Down
34 changes: 17 additions & 17 deletions tests/unit/s2n_client_key_share_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(int argc, char **argv)

/* Test that s2n_extensions_key_share_size produces the expected constant result */
{
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));

Expand All @@ -75,7 +75,7 @@ int main(int argc, char **argv)
{
/* Test that s2n_client_key_share_extension.send initializes the client key share list */
{
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&key_share_extension, 0));
Expand All @@ -96,7 +96,7 @@ int main(int argc, char **argv)

/* Test that s2n_client_key_share_extension.send writes a well-formed list of key shares */
{
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&key_share_extension, 0));
Expand Down Expand Up @@ -129,7 +129,7 @@ int main(int argc, char **argv)
/* Test s2n_client_key_share_extension.send for a supported curve present in s2n_all_supported_curves_list,
* but not present in the ecc_preferences list selected */
if (s2n_is_evp_apis_supported()) {
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_connection *conn;
struct s2n_config *config;
EXPECT_NOT_NULL(config = s2n_config_new());
Expand Down Expand Up @@ -180,7 +180,7 @@ int main(int argc, char **argv)
if (s2n_is_evp_apis_supported()) {
struct s2n_connection *conn;
struct s2n_config *config;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };

EXPECT_NOT_NULL(config = s2n_config_new());
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
Expand Down Expand Up @@ -239,7 +239,7 @@ int main(int argc, char **argv)
{
struct s2n_connection *client_conn;
struct s2n_connection *server_conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };

EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
Expand Down Expand Up @@ -290,7 +290,7 @@ int main(int argc, char **argv)
* if the server negotiated_curve is not set and is NULL. */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };

EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));

Expand Down Expand Up @@ -387,7 +387,7 @@ int main(int argc, char **argv)
* the result of s2n_client_key_share_extension.send */
{
struct s2n_connection *client_conn, *server_conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };

EXPECT_NOT_NULL(client_conn = s2n_connection_new(S2N_CLIENT));
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
Expand Down Expand Up @@ -670,7 +670,7 @@ int main(int argc, char **argv)
* than available data */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
conn->actual_protocol_version = S2N_TLS13;
EXPECT_OK(s2n_set_all_mutually_supported_groups(conn));
Expand All @@ -692,7 +692,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv errors on key share size longer than data */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
conn->actual_protocol_version = S2N_TLS13;
EXPECT_OK(s2n_set_all_mutually_supported_groups(conn));
Expand All @@ -717,7 +717,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv accepts a subset of supported curves */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
conn->actual_protocol_version = S2N_TLS13;
EXPECT_OK(s2n_set_all_mutually_supported_groups(conn));
Expand Down Expand Up @@ -750,7 +750,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv handles empty client share list */
{
struct s2n_connection *server_conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_connection_set_all_protocol_versions(server_conn, S2N_TLS13));
EXPECT_OK(s2n_set_all_mutually_supported_groups(server_conn));
Expand All @@ -776,7 +776,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv ignores unsupported curves */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_connection_set_all_protocol_versions(conn, S2N_TLS13));
EXPECT_OK(s2n_set_all_mutually_supported_groups(conn));
Expand Down Expand Up @@ -815,7 +815,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv ignores curves with incorrect key size */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
EXPECT_SUCCESS(s2n_connection_set_all_protocol_versions(conn, S2N_TLS13));
EXPECT_OK(s2n_set_all_mutually_supported_groups(conn));
Expand Down Expand Up @@ -848,7 +848,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv uses first instance of duplicate curves */
{
struct s2n_connection *server_conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_ecc_evp_params first_params, second_params;
int supported_curve_index = 0;
EXPECT_NOT_NULL(server_conn = s2n_connection_new(S2N_SERVER));
Expand Down Expand Up @@ -892,7 +892,7 @@ int main(int argc, char **argv)
/* Test that s2n_client_key_share_extension.recv ignores ECDHE points that can't be parsed */
{
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_config *config;
EXPECT_NOT_NULL(config = s2n_config_new());
/* Explicitly set the ecc_preferences list to only contain the curves p-256 and p-384 */
Expand Down Expand Up @@ -1045,7 +1045,7 @@ int main(int argc, char **argv)
{
if (s2n_is_evp_apis_supported()) {
struct s2n_connection *conn;
struct s2n_stuffer key_share_extension;
struct s2n_stuffer key_share_extension = { 0 };
struct s2n_config *config;
EXPECT_NOT_NULL(config = s2n_config_new());
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/s2n_client_max_frag_len_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_config_send_max_fragment_length(config, S2N_TLS_MAX_FRAG_LEN_512));
Expand All @@ -76,7 +76,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_config_send_max_fragment_length(config, S2N_TLS_MAX_FRAG_LEN_512));
Expand Down Expand Up @@ -110,7 +110,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

/* Send invalid mfl code */
Expand All @@ -137,7 +137,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_config(conn, config));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_config_send_max_fragment_length(conn->config, S2N_TLS_MAX_FRAG_LEN_512));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_client_pq_kem_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, pq_security_policy_version));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_pq_kem_extension.send(conn, &stuffer));
Expand Down Expand Up @@ -88,7 +88,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, pq_security_policy_version));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_pq_kem_extension.send(conn, &stuffer));
Expand All @@ -108,7 +108,7 @@ int main(int argc, char **argv)
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_CLIENT));
EXPECT_SUCCESS(s2n_connection_set_cipher_preferences(conn, pq_security_policy_version));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_client_pq_kem_extension.send(conn, &stuffer));
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/s2n_client_renegotiation_info_extension_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_stuffer_write_uint16(&stuffer, 0));
Expand All @@ -66,7 +66,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_stuffer_write_uint8(&stuffer, 1));
Expand All @@ -84,7 +84,7 @@ int main(int argc, char **argv)
struct s2n_connection *conn;
EXPECT_NOT_NULL(conn = s2n_connection_new(S2N_SERVER));

struct s2n_stuffer stuffer;
struct s2n_stuffer stuffer = { 0 };
EXPECT_SUCCESS(s2n_stuffer_growable_alloc(&stuffer, 0));

EXPECT_SUCCESS(s2n_stuffer_write_uint8(&stuffer, 0));
Expand Down
Loading

0 comments on commit 4aec93c

Please sign in to comment.