patch 9.1.1722: compiler may optimize away clearing of crypt key
Commit:
https://github.com/vim/vim/commit/59d496ab0cca1a1608d15344ebe072b0e360afb3
Author: ashamedbit <[email protected]>
Date: Sun Aug 31 20:05:23 2025 +0200
patch 9.1.1722: compiler may optimize away clearing of crypt key
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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/crypt.c b/src/crypt.c
index 55edd6c6d..3063afdff 100644
--- a/src/crypt.c
+++ b/src/crypt.c
@@ -780,12 +780,17 @@ crypt_decode_inplace(
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);
}
}
diff --git a/src/version.c b/src/version.c
index 2ce3628bf..042b995aa 100644
--- a/src/version.c
+++ b/src/version.c
@@ -724,6 +724,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1722,
/**/
1721,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1usmZz-00DcnJ-As%40256bit.org.