From aa0971addcb4600262e4922bdc29b250035002b2 Mon Sep 17 00:00:00 2001 From: Boquan Fang Date: Fri, 11 Oct 2024 17:04:31 +0000 Subject: [PATCH] fix: fix s2n_io_pair_close_one_end * add checking logics for s2n_io_pair_close_one_end() --- tests/testlib/s2n_connection_test_utils.c | 6 ++++-- tests/testlib/s2n_testlib.h | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/testlib/s2n_connection_test_utils.c b/tests/testlib/s2n_connection_test_utils.c index bc6c2db2283..7e3d464621c 100644 --- a/tests/testlib/s2n_connection_test_utils.c +++ b/tests/testlib/s2n_connection_test_utils.c @@ -187,10 +187,12 @@ int s2n_io_pair_close(struct s2n_test_io_pair *io_pair) 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)); - } 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 = S2N_CLOSED_FD; } return 0; } diff --git a/tests/testlib/s2n_testlib.h b/tests/testlib/s2n_testlib.h index ec9a3a36b7f..5f91d2302dd 100644 --- a/tests/testlib/s2n_testlib.h +++ b/tests/testlib/s2n_testlib.h @@ -20,6 +20,8 @@ #include "stuffer/s2n_stuffer.h" #include "tls/s2n_connection.h" +#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;