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

fix mem leaks with invalid TLS configs #264

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion c_src/quicer_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ ClientLoadConfiguration(ErlNifEnv *env,
// If Verify Peer...
if (!parse_verify_options(env, *options, &CredConfig, FALSE, NULL))
{
return ERROR_TUPLE_2(ATOM_VERIFY);
ret = ATOM_VERIFY;
goto done;
}

unsigned alpn_buffer_length = 0;
Expand Down
6 changes: 5 additions & 1 deletion c_src/quicer_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,11 @@ async_connect3(ErlNifEnv *env,
if (!IS_SAME_TERM(ATOM_OK, estatus))
{
res = ERROR_TUPLE_2(estatus);
goto Error;
if (!is_reuse_handle)
{
enif_release_resource(c_ctx);
}
return ERROR_TUPLE_2(ATOM_QUIC_REGISTRATION);
}

if (!is_reuse_handle)
Expand Down
2 changes: 2 additions & 0 deletions c_src/quicer_listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ start_listener3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])

if (!IS_SAME_TERM(ret, ATOM_OK))
{
enif_release_resource(new_config_ctx);
return ERROR_TUPLE_2(ret);
}

Expand All @@ -600,6 +601,7 @@ start_listener3(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
if (!l_ctx->Listener)
{
ret = ERROR_TUPLE_2(ATOM_CLOSED);
enif_release_resource(new_config_ctx);
goto exit;
}

Expand Down
18 changes: 12 additions & 6 deletions c_src/quicer_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ parse_cert_options(ErlNifEnv *env,
if (!(certfile
= str_from_map(env, ATOM_CERTFILE, &options, NULL, PATH_MAX + 1)))
{
return FALSE;
goto error;
}
if (!(keyfile
= str_from_map(env, ATOM_KEYFILE, &options, NULL, PATH_MAX + 1)))
{
return FALSE;
goto error;
}

// Get password for Server CertFile
if (enif_get_map_value(env, options, ATOM_PASSWORD, &tmp_term))
{
if (!(password = str_from_map(env, ATOM_PASSWORD, &options, NULL, 256)))
{
return FALSE;
goto error;
}

QUIC_CERTIFICATE_FILE_PROTECTED *CertFile
Expand All @@ -59,7 +59,7 @@ parse_cert_options(ErlNifEnv *env,

if (!CertFile)
{
return FALSE;
goto error;
}
CertFile->CertificateFile = certfile;
CertFile->PrivateKeyFile = keyfile;
Expand All @@ -74,7 +74,7 @@ parse_cert_options(ErlNifEnv *env,
sizeof(QUIC_CERTIFICATE_FILE), QUICER_CERTIFICATE_FILE);
if (!CertFile)
{
return FALSE;
goto error;
}
CertFile->CertificateFile = certfile;
CertFile->PrivateKeyFile = keyfile;
Expand All @@ -83,6 +83,11 @@ parse_cert_options(ErlNifEnv *env,
}

return TRUE;
error:
free(certfile);
free(keyfile);
free(password);
return FALSE;
}

/*
Expand Down Expand Up @@ -330,7 +335,8 @@ eoptions_to_cred_config(ErlNifEnv *env,
// Handle the certificate, key, password options
if (!parse_cert_options(env, eoptions, CredConfig))
{
return ATOM_QUIC_TLS;
ret = ATOM_QUIC_TLS;
goto exit;
}

// Handle the `verify` options
Expand Down
Loading