This guarantees that the compiler will not optimize away the memset()
call if it detects a dead store.
Use this to clear SSL passphrases.
No backport needed.
void ha_freearray(char ***array);
+void ha_memset_s(void *s, int c, size_t n);
+
#endif /* _HAPROXY_TOOLS_H */
/* Erase stored passphrases just in case some memory
* ends up leaking */
- memset(passphrase_cache[idx].ptr, 0, passphrase_cache[idx].len);
+ ha_memset_s(passphrase_cache[idx].ptr, 0, passphrase_cache[idx].len);
istfree(&passphrase_cache[idx]);
}
ha_free(&passphrase_cache);
*array = NULL;
}
+/*
+ * Secure implementation of memset that cannot be optimized away.
+ */
+void ha_memset_s(void *s, int c, size_t n)
+{
+ memset(s, c, n);
+ __asm__ __volatile__("" : : "r"(s) : "memory");
+}
+
/*
* Local variables:
* c-indent-level: 8