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 possible leaks in examples/echo #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 0 deletions examples/echo/echo-keygen/echo-keygen.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ int main(int argc, char *argv[])
pub_key = (uint8_t *)malloc(pub_key_len);
if (!priv_key || !pub_key) {
fprintf(stderr, "Out of memory\n");
noise_free(priv_key, priv_key_len);
noise_free(pub_key, pub_key_len);
noise_dhstate_free(dh);
return 1;
}
err = noise_dhstate_get_keypair
Expand Down
6 changes: 4 additions & 2 deletions examples/echo/echo-server/echo-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,14 @@ int echo_to_noise_protocol_id(NoiseProtocolId *nid, const EchoProtocolId *id)
/* Loads a binary private key from a file. Returns non-zero if OK. */
int echo_load_private_key(const char *filename, uint8_t *key, size_t len)
{
FILE *file = fopen(filename, "rb");
FILE *file;
size_t posn = 0;
int ch;
if (len > MAX_DH_KEY_LEN) {
fprintf(stderr, "private key length is not supported\n");
return 0;
}
file = fopen(filename, "rb");
if (!file) {
perror(filename);
return 0;
Expand All @@ -242,7 +243,7 @@ int echo_load_private_key(const char *filename, uint8_t *key, size_t len)
/* Loads a base64-encoded public key from a file. Returns non-zero if OK. */
int echo_load_public_key(const char *filename, uint8_t *key, size_t len)
{
FILE *file = fopen(filename, "rb");
FILE *file;
uint32_t group = 0;
size_t group_size = 0;
uint32_t digit = 0;
Expand All @@ -252,6 +253,7 @@ int echo_load_public_key(const char *filename, uint8_t *key, size_t len)
fprintf(stderr, "public key length is not supported\n");
return 0;
}
file = fopen(filename, "rb");
if (!file) {
perror(filename);
return 0;
Expand Down