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

Bugs in example program pk_encrypt.c #1128

Closed
RonEld opened this issue Oct 8, 2017 · 2 comments
Closed

Bugs in example program pk_encrypt.c #1128

RonEld opened this issue Oct 8, 2017 · 2 comments
Labels

Comments

@RonEld
Copy link
Contributor

RonEld commented Oct 8, 2017

Description

  • Type: Bug
  • Priority: Minor
    Raised via Email by Brace Stout

Bug

OS
linux

mbed TLS build:
Version: development branch

I was looking through the example programs trying to get an idea of how to use the PK wrapper to abstract the RSA/EC functions, and think there are some issues with the pk_encrypt.c example program. This is probably low priority, but as an example program, it should be an example of proper use.
Specifically, the following code occurs at the exit label:

exit:
mbedtls_ctr_drbg_free( &ctr_drbg );
mbedtls_entropy_free( &entropy );

In some code paths, entropy is not yet initialized.
Similarly, the mbedtls_pk_context variable pk is never freed, even when it is initialized.
Two approaches to addressing these problems come immediately to mind:

  1. init everything at the same time: ctr_drbg, entropy, and pk and then free them all at the same time (at the exit label), or
  2. have three separate exit labels (e.g. exitA, exitB, exitC) and branch to whichever is appropriate at the point an error is encountered.
exitA:
mbedtls_pk_free( &pk );
exitB:
mbedtls_entropy_free( &entropy );
exitC:
mbedtls_ctr_drbg_free( &ctr_drbg );
@ciarmcom
Copy link

ciarmcom commented Oct 9, 2017

ARM Internal Ref: IOTSSL-1806

@simonbutcher
Copy link
Contributor

simonbutcher commented Sep 13, 2018

PR #1129 which fixes this problem has now been merged so this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants