summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-03-02 17:55:51 +0100
committerAndreas Schneider <asn@cryptomilk.org>2018-03-02 18:07:42 +0100
commit81847bf5135d836000d206d559df2e27f9a00a84 (patch)
tree16824a3f76f933df790ad5d221388e1e5d7c1f54
parentbba40abc7603fbb3e4f5089684845312b789aff7 (diff)
downloadlibssh-81847bf5135d836000d206d559df2e27f9a00a84.tar.gz
libssh-81847bf5135d836000d206d559df2e27f9a00a84.tar.xz
libssh-81847bf5135d836000d206d559df2e27f9a00a84.zip
priv: Implement explicit_bzero as a function if not available
Signed-off-by: Andreas Schneider <asn@cryptomilk.org> Reviewed-by: Alberto Aguirre <albaguirre@gmail.com>
-rw-r--r--ConfigureChecks.cmake2
-rw-r--r--include/libssh/priv.h16
-rw-r--r--src/misc.c11
3 files changed, 13 insertions, 16 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 4b03d537..b008d5c3 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -291,7 +291,7 @@ int main(void)
{
char buf[] = \"This is some content\";
- memset(buf, '\\\\0', sizeof(buf)); __asm__ volatile(\"\" : : \"r\"(&buf) : \"memory\");
+ memset(buf, '\\\\0', sizeof(buf)); __asm__ volatile(\"\" : : \"g\"(&buf) : \"memory\");
return 0;
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
diff --git a/include/libssh/priv.h b/include/libssh/priv.h
index d191a9f5..f99e769e 100644
--- a/include/libssh/priv.h
+++ b/include/libssh/priv.h
@@ -281,21 +281,7 @@ int ssh_connector_remove_event(ssh_connector connector);
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
#ifndef HAVE_EXPLICIT_BZERO
-/*
- * See http://llvm.org/bugs/show_bug.cgi?id=15495
- */
-#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
-#define explicit_bzero(s, n) do { \
- if ((s) != NULL) { \
- void *_x = (s); \
- memset((_x), '\0', (n)); __asm__ volatile("" : : "r"(&(_x)) : "memory"); \
- } \
-} while (0)
-#else /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
-#define explicit_bzero(s, n) do { \
- memset((s), '\0', (n)); \
-} while (0)
-#endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
+void explicit_bzero(void *s, size_t n);
#endif /* !HAVE_EXPLICIT_BZERO */
/**
diff --git a/src/misc.c b/src/misc.c
index 9ef31184..ac3a623c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -1052,6 +1052,17 @@ int ssh_match_group(const char *group, const char *object)
return 0;
}
+#if !defined(HAVE_EXPLICIT_BZERO)
+void explicit_bzero(void *s, size_t n)
+{
+ memset(s, '\0', n);
+#if defined(HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
+ /* See http://llvm.org/bugs/show_bug.cgi?id=15495 */
+ __asm__ volatile("" : : "g"(s) : "memory");
+#endif /* HAVE_GCC_VOLATILE_MEMORY_PROTECTION */
+}
+#endif /* !HAVE_EXPLICIT_BZERO */
+
/** @} */
/* vim: set ts=4 sw=4 et cindent: */