Skip to content

Commit

Permalink
fix: address PR comments
Browse files Browse the repository at this point in the history
* add checking logics for s2n_io_pair_close_one_end()
  • Loading branch information
Boquan Fang committed Oct 11, 2024
1 parent b1f4916 commit 891da38
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
16 changes: 6 additions & 10 deletions tests/testlib/s2n_connection_test_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,19 @@ int s2n_connections_set_io_pair(struct s2n_connection *client, struct s2n_connec

int s2n_io_pair_close(struct s2n_test_io_pair *io_pair)
{
if (io_pair->client != CLOSED_FD) {
POSIX_GUARD(s2n_io_pair_close_one_end(io_pair, S2N_CLIENT));
}
if (io_pair->server != CLOSED_FD) {
POSIX_GUARD(s2n_io_pair_close_one_end(io_pair, S2N_SERVER));
}
POSIX_GUARD(s2n_io_pair_close_one_end(io_pair, S2N_CLIENT));
POSIX_GUARD(s2n_io_pair_close_one_end(io_pair, S2N_SERVER));
return 0;
}

int s2n_io_pair_close_one_end(struct s2n_test_io_pair *io_pair, int mode_to_close)
{
if (mode_to_close == S2N_CLIENT) {
if (mode_to_close == S2N_CLIENT && io_pair->client != S2N_CLOSED_FD) {
POSIX_GUARD(close(io_pair->client));
io_pair->client = CLOSED_FD;
} else if (mode_to_close == S2N_SERVER) {
io_pair->client = S2N_CLOSED_FD;
} else if (mode_to_close == S2N_SERVER && io_pair->server != S2N_CLOSED_FD) {
POSIX_GUARD(close(io_pair->server));
io_pair->server = CLOSED_FD;
io_pair->server = S2N_CLOSED_FD;
}
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testlib/s2n_testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "stuffer/s2n_stuffer.h"
#include "tls/s2n_connection.h"

#define CLOSED_FD -1
#define S2N_CLOSED_FD -1

extern const struct s2n_ecc_preferences ecc_preferences_for_retry;
extern const struct s2n_security_policy security_policy_test_tls13_retry;
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/s2n_ktls_io_sendfile_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,10 @@ int main(int argc, char **argv)
DEFER_CLEANUP(struct s2n_test_io_pair io_pair = { 0 }, s2n_io_pair_close);
EXPECT_SUCCESS(s2n_io_pair_init_non_blocking(&io_pair));
int write_fd = io_pair.server;
int read_fd = io_pair.client;
EXPECT_SUCCESS(s2n_connection_set_write_fd(conn, write_fd));

/* Close one side of the stream to make the fds invalid */
s2n_io_pair_close_one_end(&io_pair, S2N_CLIENT);
read_fd = CLOSED_FD;

s2n_blocked_status blocked = S2N_NOT_BLOCKED;
size_t bytes_written = 0;
Expand Down

0 comments on commit 891da38

Please sign in to comment.