mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
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>
This commit is contained in:
@@ -291,7 +291,7 @@ int main(void)
|
|||||||
{
|
{
|
||||||
char buf[] = \"This is some content\";
|
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;
|
return 0;
|
||||||
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
}" HAVE_GCC_VOLATILE_MEMORY_PROTECTION)
|
||||||
|
|||||||
@@ -281,21 +281,7 @@ int ssh_connector_remove_event(ssh_connector connector);
|
|||||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
|
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
|
||||||
|
|
||||||
#ifndef HAVE_EXPLICIT_BZERO
|
#ifndef HAVE_EXPLICIT_BZERO
|
||||||
/*
|
void explicit_bzero(void *s, size_t n);
|
||||||
* 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 */
|
|
||||||
#endif /* !HAVE_EXPLICIT_BZERO */
|
#endif /* !HAVE_EXPLICIT_BZERO */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
11
src/misc.c
11
src/misc.c
@@ -1052,6 +1052,17 @@ int ssh_match_group(const char *group, const char *object)
|
|||||||
return 0;
|
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: */
|
/* vim: set ts=4 sw=4 et cindent: */
|
||||||
|
|||||||
Reference in New Issue
Block a user