Problem: Compiler may optimize away clearing of crypt key
Solution: Use sodium_memzero() if available, else use memset() using a
volatile function pointer (ashamedbit).
closes: #18173
Signed-off-by: ashamedbit <muralianiruddhan@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
void
crypt_free_key(char_u *key)
{
- char_u *p;
-
+ // Create a safe memset which cannot be optimized away by compiler
+ static void *(* volatile vim_memset_safe)(void *s, int c, size_t n) =
+ memset;
if (key != NULL)
{
- for (p = key; *p != NUL; ++p)
- *p = 0;
+#ifdef FEAT_SODIUM
+ if (sodium_init() >= 0)
+ sodium_memzero(key, STRLEN(key));
+ else
+#endif
+ vim_memset_safe(key, 0, STRLEN(key));
vim_free(key);
}
}
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1722,
/**/
1721,
/**/