summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.c9
-rw-r--r--src/util/util.h9
2 files changed, 18 insertions, 0 deletions
diff --git a/src/util/util.c b/src/util/util.c
index b035e2319..ba85e0da2 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 e4cb1a865..cc5a2bafb 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);