diff options
author | Aris Adamantiadis <aris@0xbadc0de.be> | 2016-01-01 19:16:49 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-07-05 14:35:13 +0200 |
commit | db9da99a36a4d83b77f8f8e90482c2d6cc0e20de (patch) | |
tree | 46a2f939941cc85e736de5627e7430cf4e2937f7 /include/libssh/libmbedcrypto.h | |
parent | c3dac948c916c1330419980f71a72c253efd19b8 (diff) | |
download | libssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.tar.gz libssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.tar.xz libssh-db9da99a36a4d83b77f8f8e90482c2d6cc0e20de.zip |
bignum: Make bignum_free safer
Signed-off-by: Aris Adamantiadis <aris@0xbadc0de.be>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'include/libssh/libmbedcrypto.h')
-rw-r--r-- | include/libssh/libmbedcrypto.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/include/libssh/libmbedcrypto.h b/include/libssh/libmbedcrypto.h index 101cdee9..7522cd14 100644 --- a/include/libssh/libmbedcrypto.h +++ b/include/libssh/libmbedcrypto.h @@ -78,7 +78,12 @@ int ssh_mbedcry_rand(bignum rnd, int bits, int top, int bottom); int ssh_mbedcry_is_bit_set(bignum num, size_t pos); #define bignum_new() ssh_mbedcry_bn_new() -#define bignum_free(num) ssh_mbedcry_bn_free(num); +#define bignum_safe_free(num) do { \ + if ((num) != NULL) { \ + ssh_mbedcry_bn_free(num); \ + (num)=NULL; \ + } \ + } while(0) #define bignum_set_word(bn, n) mbedtls_mpi_lset(bn, n) /* TODO fix overflow/underflow */ #define bignum_bin2bn(data, datalen, bn) mbedtls_mpi_read_binary(bn, data, \ |