diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/util/util.c | 9 | ||||
-rw-r--r-- | src/util/util.h | 9 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c index b035e231..ba85e0da 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -679,3 +679,12 @@ bool string_in_list(const char *string, char **list, bool case_sensitive) return false; } + +void safezero(void *data, size_t size) +{ + volatile uint8_t *p = data; + + while (size--) { + *p++ = 0; + } +} diff --git a/src/util/util.h b/src/util/util.h index e4cb1a86..cc5a2baf 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -541,6 +541,15 @@ errno_t add_string_to_list(TALLOC_CTX *mem_ctx, const char *string, bool string_in_list(const char *string, char **list, bool case_sensitive); +/** + * @brief Safely zero a segment of memory, + * prevents the compiler from optimizing out + * + * @param data The address of buffer to wipe + * @param s Size of the buffer + */ +void safezero(void *data, size_t size); + /* from sss_tc_utf8.c */ char * sss_tc_utf8_str_tolower(TALLOC_CTX *mem_ctx, const char *s); |