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

Conversation

niooss-ledger
Copy link

Hello,

While trying to use noise-c in some projects based on the given examples, I found some issues which happen in rare error conditions. It would be useful if the issues were fixed in the examples, so that projects which are inspired by them start on a good basis. This is why I am opening this Pull Request.

Please see the descriptions of each commit for more information about the fixed issues.

Anyway, thanks for this awesome project!

In both `echo_load_private_key` and `echo_load_public_key`, when
`len > MAX_DH_KEY_LEN`, the opened file is not closed before the
function returns.

Fix this possible resource leak by opening the file after checking `len`.

This bug was found using clang's static analyzer:

    scan-build -enable-checker alpha.unix.Stream make
If either `priv_key` or `pub_key` is `NULL` but not the other one, the
allocated memory is not freed. This issue is reported by clang's static
analyzer.

Fix this by calling `noise_free` in the error block.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant