Skip to content

Commit

Permalink
refactor: fix unread variable warnings (aws#4405)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmayclin authored Mar 1, 2024
1 parent 91ad940 commit 74e66fd
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 38 deletions.
6 changes: 2 additions & 4 deletions tests/testlib/s2n_test_server_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ int s2n_negotiate_test_server_and_client(struct s2n_connection *server_conn, str
{
bool server_done = false, client_done = false;
s2n_blocked_status blocked = S2N_NOT_BLOCKED;
bool rc = false;

do {
rc = (s2n_negotiate(client_conn, &blocked) >= S2N_SUCCESS);
bool rc = (s2n_negotiate(client_conn, &blocked) >= S2N_SUCCESS);
POSIX_GUARD_RESULT(s2n_validate_negotiate_result(rc, server_done, &client_done));

rc = (s2n_negotiate(server_conn, &blocked) >= S2N_SUCCESS);
Expand Down Expand Up @@ -105,10 +104,9 @@ S2N_RESULT s2n_negotiate_test_server_and_client_until_message(struct s2n_connect
{
bool server_done = false, client_done = false;
s2n_blocked_status blocked = S2N_NOT_BLOCKED;
bool rc = false;

do {
rc = s2n_result_is_ok(s2n_negotiate_until_message(client_conn, &blocked, message_type));
bool rc = s2n_result_is_ok(s2n_negotiate_until_message(client_conn, &blocked, message_type));
RESULT_GUARD(s2n_validate_negotiate_result(rc, server_done, &client_done));

rc = s2n_result_is_ok(s2n_negotiate_until_message(server_conn, &blocked, message_type));
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/s2n_alerts_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ int main(int argc, char **argv)
/* Test S2N_ERR_T_PROTO */
{
/* Test all protocol errors are handled */
int ret_val;
for (size_t i = S2N_ERR_T_PROTO_START; i < S2N_ERR_T_PROTO_END; i++) {
ret_val = s2n_error_get_alert(i, &alert);
int ret_val = s2n_error_get_alert(i, &alert);
if (ret_val != S2N_SUCCESS && s2n_errno == S2N_ERR_UNIMPLEMENTED) {
fprintf(stdout, "\n\nNo alert mapping for protocol error %s\n\n", s2n_strerror_name(i));
FAIL_MSG("Missing alert mapping for protocol error.");
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/s2n_mem_allocator_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ int main(int argc, char **argv)
{
s2n_blocked_status blocked;
int status;
pid_t pid;
char *cert_chain_pem;
char *private_key_pem;
char *dhparams_pem;
Expand All @@ -175,7 +174,7 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));

/* Create a child process */
pid = fork();
pid_t pid = fork();
if (pid == 0) {
/* This is the client process, close the server end of the pipe */
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/s2n_self_talk_broken_pipe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ int main(int argc, char **argv)
struct s2n_config *config;
s2n_blocked_status blocked;
int status;
pid_t pid;
char cert_chain_pem[S2N_MAX_TEST_PEM_SIZE];
char private_key_pem[S2N_MAX_TEST_PEM_SIZE];
char dhparams_pem[S2N_MAX_TEST_PEM_SIZE];
Expand All @@ -107,7 +106,7 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));

/* Create a child process */
pid = fork();
pid_t pid = fork();
if (pid == 0) {
/* This is the client process, close the server end of the pipe */
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/s2n_self_talk_min_protocol_version_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ int main(int argc, char **argv)
{
s2n_blocked_status blocked;
int status;
pid_t pid;
char cert_chain_pem[S2N_MAX_TEST_PEM_SIZE];
char private_key_pem[S2N_MAX_TEST_PEM_SIZE];

Expand All @@ -82,7 +81,7 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));

/* Create a child process */
pid = fork();
pid_t pid = fork();
if (pid == 0) {
/* This is the client process, close the server end of the pipe */
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/s2n_self_talk_tls12_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ int main(int argc, char **argv)
struct s2n_config *config;
s2n_blocked_status blocked;
int status;
pid_t pid;
char *cert_chain_pem;
char *private_key_pem;
char *dhparams_pem;
Expand All @@ -117,7 +116,7 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_io_pair_init(&io_pair));

/* Create a child process */
pid = fork();
pid_t pid = fork();
if (pid == 0) {
/* This is the client process, close the server end of the pipe */
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_SERVER));
Expand Down
11 changes: 4 additions & 7 deletions tests/unit/s2n_tls12_handshake_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,21 +492,18 @@ int main(int argc, char **argv)

/* Test: A WITH_NPN form of every valid, negotiated handshake exists */
{
uint32_t handshake_type_original, handshake_type_npn;
message_type_t *messages_original, *messages_npn;

for (size_t i = 0; i < valid_tls12_handshakes_size; i++) {
handshake_type_original = valid_tls12_handshakes[i];
messages_original = handshakes[handshake_type_original];
uint32_t handshake_type_original = valid_tls12_handshakes[i];
message_type_t *messages_original = handshakes[handshake_type_original];

/* Ignore INITIAL and WITH_NPN handshakes */
if (!(handshake_type_original & NEGOTIATED) || (handshake_type_original & WITH_NPN)) {
continue;
}

/* Get the WITH_NPN form of the handshake */
handshake_type_npn = handshake_type_original | WITH_NPN;
messages_npn = handshakes[handshake_type_npn];
uint32_t handshake_type_npn = handshake_type_original | WITH_NPN;
message_type_t *messages_npn = handshakes[handshake_type_npn];

for (size_t j = 0, j_npn = 0; j < S2N_MAX_HANDSHAKE_LENGTH && j_npn < S2N_MAX_HANDSHAKE_LENGTH; j++, j_npn++) {
/* The original handshake cannot contain the Next Protocol message */
Expand Down
20 changes: 8 additions & 12 deletions tests/unit/s2n_tls13_handshake_state_machine_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,6 @@ int main(int argc, char **argv)
*# the TLS 1.3 handshake look more like a TLS 1.2 handshake:
*/
{
bool change_cipher_spec_found;
uint32_t handshake_type;
message_type_t *messages;

/*
*= https://tools.ietf.org/rfc/rfc8446#appendix-D.4
*= type=test
Expand All @@ -668,9 +664,9 @@ int main(int argc, char **argv)
*# its second ClientHello or before its encrypted handshake flight.
**/
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
change_cipher_spec_found = false;
handshake_type = valid_tls13_handshakes[i];
messages = tls13_handshakes[handshake_type];
bool change_cipher_spec_found = false;
uint32_t handshake_type = valid_tls13_handshakes[i];
message_type_t *messages = tls13_handshakes[handshake_type];

/* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
if (!(handshake_type & NEGOTIATED)
Expand Down Expand Up @@ -705,8 +701,8 @@ int main(int argc, char **argv)
*# first ClientHello.
*/
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
handshake_type = valid_tls13_handshakes[i];
messages = tls13_handshakes[handshake_type];
uint32_t handshake_type = valid_tls13_handshakes[i];
message_type_t *messages = tls13_handshakes[handshake_type];

/* Ignore handshakes where early data did not trigger the change in CCS behavior */
if (!(handshake_type & EARLY_CLIENT_CCS)) {
Expand All @@ -728,9 +724,9 @@ int main(int argc, char **argv)
*# ServerHello or a HelloRetryRequest.
**/
for (size_t i = 0; i < valid_tls13_handshakes_size; i++) {
change_cipher_spec_found = false;
handshake_type = valid_tls13_handshakes[i];
messages = tls13_handshakes[handshake_type];
bool change_cipher_spec_found = false;
uint32_t handshake_type = valid_tls13_handshakes[i];
message_type_t *messages = tls13_handshakes[handshake_type];

/* Ignore INITIAL and non-MIDDLEBOX_COMPAT handshakes */
if (!(handshake_type & NEGOTIATED) || !(handshake_type & MIDDLEBOX_COMPAT)) {
Expand Down
6 changes: 1 addition & 5 deletions tls/s2n_protocol_preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ S2N_RESULT s2n_protocol_preferences_set(struct s2n_blob *application_protocols,
/* update the connection/config application_protocols with the newly allocated blob */
*application_protocols = new_protocols;

/* zero out new_protocols so the DEFER_CLEANUP from above doesn't free
* the blob that we created and assigned to application_protocols
*/
/* cppcheck-suppress unreadVariable */
new_protocols = (struct s2n_blob){ 0 };
ZERO_TO_DISABLE_DEFER_CLEANUP(new_protocols);

return S2N_RESULT_OK;
}
Expand Down

0 comments on commit 74e66fd

Please sign in to comment.