diff options
author | George Kadianakis <desnacked@riseup.net> | 2020-08-11 14:53:03 +0300 |
---|---|---|
committer | George Kadianakis <desnacked@riseup.net> | 2020-08-11 14:53:03 +0300 |
commit | ab9c35f04353c00323068ec5dc46b2995a9b69bf (patch) | |
tree | 390a3b4f064551449dddd4474fe7f2a6c2bc7b89 /src/lib/crypt_ops | |
parent | 7d80bf80fe9017e04fff4b588f49d0393332ebee (diff) | |
parent | ea876ab00e223b0c1ba022cc27861cfbbde31b64 (diff) | |
download | tor-ab9c35f04353c00323068ec5dc46b2995a9b69bf.tar.gz tor-ab9c35f04353c00323068ec5dc46b2995a9b69bf.zip |
Merge remote-tracking branch 'tor-gitlab/mr/102' into maint-0.4.4
Diffstat (limited to 'src/lib/crypt_ops')
-rw-r--r-- | src/lib/crypt_ops/crypto_util.c | 14 | ||||
-rw-r--r-- | src/lib/crypt_ops/crypto_util.h | 10 |
2 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/crypt_ops/crypto_util.c b/src/lib/crypt_ops/crypto_util.c index 60e81af165..7ebb860d09 100644 --- a/src/lib/crypt_ops/crypto_util.c +++ b/src/lib/crypt_ops/crypto_util.c @@ -107,3 +107,17 @@ memwipe(void *mem, uint8_t byte, size_t sz) **/ memset(mem, byte, sz); } + +/** + * Securely all memory in <b>str</b>, then free it. + * + * As tor_free(), tolerates null pointers. + **/ +void +tor_str_wipe_and_free_(char *str) +{ + if (!str) + return; + memwipe(str, 0, strlen(str)); + tor_free_(str); +} diff --git a/src/lib/crypt_ops/crypto_util.h b/src/lib/crypt_ops/crypto_util.h index 4c08180f92..36ee230176 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) */ |