util: git__memzero() tweaks On Linux: fix a warning message related to the volatile qualifier (cast) On Windows: use SecureZeroMemory() On both, inline the call, so that no entry point can lead back to this "secure" memory zeroing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/util.c b/src/util.c
index 1d084da..da15a03 100644
--- a/src/util.c
+++ b/src/util.c
@@ -722,12 +722,3 @@ void git__insertsort_r(
if (freeswap)
git__free(swapel);
}
-
-void git__memzero(volatile void *data, size_t size)
-{
- volatile uint8_t *scan = data;
- uint8_t *end = scan + size;
-
- while (scan < end)
- *scan++ = 0x0;
-}
diff --git a/src/util.h b/src/util.h
index 0de4666..1ef9e65 100644
--- a/src/util.h
+++ b/src/util.h
@@ -325,6 +325,16 @@ extern size_t git__unescape(char *str);
* Safely zero-out memory, making sure that the compiler
* doesn't optimize away the operation.
*/
-extern void git__memzero(volatile void *data, size_t size);
+GIT_INLINE(void) git__memzero(void *data, size_t size)
+{
+#ifdef _MSC_VER
+ SecureZeroMemory((PVOID)data, size);
+#else
+ volatile uint8_t *scan = (volatile uint8_t *)data;
+
+ while (size--)
+ *scan++ = 0x0;
+#endif
+}
#endif /* INCLUDE_util_h__ */