Skip to content

Commit

Permalink
fix: close all /dev/urandom open fds
Browse files Browse the repository at this point in the history
  • Loading branch information
boquan-fang authored and Boquan Fang committed Oct 9, 2024
1 parent 66a3bcb commit 5c0dece
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions tests/unit/s2n_drbg_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_stuffer_free(&nist_aes256_reference_entropy));

EXPECT_SUCCESS(s2n_config_free(config));
/* Clean up with previously set functions */
POSIX_GUARD_RESULT(s2n_rand_cleanup());

END_TEST();
}
4 changes: 4 additions & 0 deletions tests/unit/s2n_fork_generation_number_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "s2n_test.h"
#include "utils/s2n_fork_detection.h"
#include "utils/s2n_random.h"

#define NUMBER_OF_FGN_TEST_CASES 4
#define MAX_NUMBER_OF_TEST_THREADS 2
Expand Down Expand Up @@ -189,6 +190,9 @@ static int s2n_unit_test_clone_child_process(void *parent_process_fgn)
/* Verify in threads */
EXPECT_EQUAL(s2n_unit_test_thread(return_fork_generation_number), S2N_SUCCESS);

/* Clean up urandom of the child process */
POSIX_GUARD_RESULT(s2n_rand_cleanup());

/* This translates to the exit code for this child process */
return EXIT_SUCCESS;
}
Expand Down
1 change: 1 addition & 0 deletions tests/unit/s2n_key_update_threads_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ static S2N_RESULT s2n_run_self_talk_test(s2n_test_scenario scenario_fn)
EXPECT_SUCCESS(s2n_connection_free(client));
EXPECT_SUCCESS(s2n_cert_chain_and_key_free(chain_and_key));
EXPECT_SUCCESS(s2n_config_free(config));
EXPECT_SUCCESS(s2n_io_pair_close_one_end(&io_pair, S2N_CLIENT));

exit(EXIT_SUCCESS);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/s2n_override_openssl_random_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ int main(int argc, char **argv)
EXPECT_SUCCESS(s2n_stuffer_free(&dhparams_in));
EXPECT_SUCCESS(s2n_stuffer_free(&test_entropy));
free(dhparams_pem);
/* Clean up with previously set functions */
POSIX_GUARD_RESULT(s2n_rand_cleanup());

END_TEST();
}
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/s2n_random_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,9 @@ static int s2n_random_invalid_urandom_fd_cb(struct random_test_case *test_case)
EXPECT_OK(s2n_rand_set_urandom_for_test());

EXPECT_TRUE(dev_urandom->fd > STDERR_FILENO);
if (test == 0) {
/* Close the file descriptor. */
EXPECT_EQUAL(close(dev_urandom->fd), 0);
} else {
/* Close the file descriptor. */
EXPECT_EQUAL(close(dev_urandom->fd), 0);
if (test != 0) {
/* Make the file descriptor invalid by pointing it to STDERR. */
dev_urandom->fd = STDERR_FILENO;
}
Expand Down
1 change: 1 addition & 0 deletions tests/unit/s2n_self_talk_broken_pipe_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void mock_client(struct s2n_test_io_pair *io_pair)
sleep(1);

s2n_io_pair_shutdown_one_end(io_pair, S2N_CLIENT, SHUT_WR);
s2n_io_pair_close_one_end(io_pair, S2N_CLIENT);

exit(0);
}
Expand Down

0 comments on commit 5c0dece

Please sign in to comment.