mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 07:07:52 +01:00
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.
This commit is contained in:
parent
c4742b89b2
commit
5b9508c9a5
2 changed files with 24 additions and 0 deletions
|
@ -109,3 +109,17 @@ memwipe(void *mem, uint8_t byte, size_t sz)
|
||||||
**/
|
**/
|
||||||
memset(mem, byte, 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);
|
||||||
|
}
|
||||||
|
|
|
@ -14,8 +14,18 @@
|
||||||
#define TOR_CRYPTO_UTIL_H
|
#define TOR_CRYPTO_UTIL_H
|
||||||
|
|
||||||
#include "lib/cc/torint.h"
|
#include "lib/cc/torint.h"
|
||||||
|
#include "lib/malloc/malloc.h"
|
||||||
|
|
||||||
/** OpenSSL-based utility functions. */
|
/** OpenSSL-based utility functions. */
|
||||||
void memwipe(void *mem, uint8_t byte, size_t sz);
|
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) */
|
#endif /* !defined(TOR_CRYPTO_UTIL_H) */
|
||||||
|
|
Loading…
Add table
Reference in a new issue