diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-08-03 10:11:03 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-08-03 10:11:03 -0400 |
commit | 5b9508c9a5d757223c62749c51eaf7453ff26691 (patch) | |
tree | 77b5989bb03a7659aac4c17e9ee85cbf51b931d8 /src/lib/crypt_ops/crypto_util.h | |
parent | c4742b89b23d58958ee0d5ca324dac5948c94bf6 (diff) | |
download | tor-5b9508c9a5d757223c62749c51eaf7453ff26691.tar.gz tor-5b9508c9a5d757223c62749c51eaf7453ff26691.zip |
Add a tor_str_wipe_and_free() function.
Frequently we want to do
if (s) {
memwipe(s, 0, sizeof(s));
tor_free(s);
}
and it's good to have a way to do this concisely.
Diffstat (limited to 'src/lib/crypt_ops/crypto_util.h')
-rw-r--r-- | src/lib/crypt_ops/crypto_util.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_util.h b/src/lib/crypt_ops/crypto_util.h index 613a1bd0dd..b5d7f62521 100644 --- a/src/lib/crypt_ops/crypto_util.h +++ b/src/lib/crypt_ops/crypto_util.h @@ -14,8 +14,18 @@ #define TOR_CRYPTO_UTIL_H #include "lib/cc/torint.h" +#include "lib/malloc/malloc.h" /** OpenSSL-based utility functions. */ void memwipe(void *mem, uint8_t byte, size_t sz); +void tor_str_wipe_and_free_(char *str); +/** + * Securely all memory in <b>str</b>, then free it. + * + * As tor_free(), tolerates null pointers, and sets <b>str</b> to NULL. + **/ +#define tor_str_wipe_and_free(str) \ + FREE_AND_NULL(char, tor_str_wipe_and_free_, (str)) + #endif /* !defined(TOR_CRYPTO_UTIL_H) */ |