Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setenv #634

Merged
merged 14 commits into from
Apr 10, 2024
31 changes: 29 additions & 2 deletions source/s2n/s2n_tls_channel_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,34 @@ AWS_IO_API const char *aws_determine_default_pki_ca_file(void) {
return NULL;
}

static struct aws_allocator *s_library_allocator = NULL;

static int s_s2n_mem_init(void) {
return S2N_SUCCESS;
}

static int s_s2n_mem_cleanup(void) {
return S2N_SUCCESS;
}

static int s_s2n_mem_malloc(void **ptr, uint32_t requested, uint32_t *allocated) {
*ptr = aws_mem_acquire(s_library_allocator, requested);
*allocated = requested;

return S2N_SUCCESS;
}

static int s_s2n_mem_free(void *ptr, uint32_t size) {
(void)size;
aws_mem_release(s_library_allocator, ptr);
return S2N_SUCCESS;
}

/* If s2n is already initialized, then we don't call s2n_init() or s2n_cleanup() ourselves */
static bool s_s2n_initialized_externally = false;

void aws_tls_init_static_state(struct aws_allocator *alloc) {
(void)alloc;
AWS_FATAL_ASSERT(alloc);
AWS_LOGF_INFO(AWS_LS_IO_TLS, "static: Initializing TLS using s2n.");

/* Disable atexit behavior, so that s2n_cleanup() fully cleans things up.
Expand All @@ -196,7 +219,11 @@ void aws_tls_init_static_state(struct aws_allocator *alloc) {
}

if (!s_s2n_initialized_externally) {
setenv("S2N_DONT_MLOCK", "1", 1);
s_library_allocator = alloc;
if (S2N_SUCCESS != s2n_mem_set_callbacks(s_s2n_mem_init, s_s2n_mem_cleanup, s_s2n_mem_malloc, s_s2n_mem_free)) {
fprintf(stderr, "s2n_mem_set_callbacks() failed: %d (%s)\n", s2n_errno, s2n_strerror(s2n_errno, "EN"));
AWS_FATAL_ASSERT(0 && "s2n_mem_set_callbacks() failed");
}

if (s2n_init() != S2N_SUCCESS) {
fprintf(stderr, "s2n_init() failed: %d (%s)\n", s2n_errno, s2n_strerror(s2n_errno, "EN"));
Expand Down
4 changes: 3 additions & 1 deletion tests/socket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,9 @@ static int s_test_outgoing_tcp_sock_error(struct aws_allocator *allocator, void

struct aws_socket_endpoint endpoint = {
.address = "127.0.0.1",
.port = 8567,
/* note: the port is completely random from testing perspective, but
* freebsd seems to firewall higher numbered ports so keeping it low */
.port = 1567,
};

struct error_test_args args = {
Expand Down