summaryrefslogtreecommitdiff
path: root/src/misc.c
diff options
context:
space:
mode:
authorJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-04 10:00:45 +0300
committerJussi Kivilinna <jussi.kivilinna@iki.fi>2013-09-04 10:00:45 +0300
commit4b0edf53440239d3bcc95941980c062a0801a149 (patch)
tree822302c176b7a052e01e9173b88df343bfc8d360 /src/misc.c
parenta3aaa6ad03388ea3eaa24304b604cb864633332f (diff)
downloadlibgcrypt-4b0edf53440239d3bcc95941980c062a0801a149.tar.gz
Make _gcry_burn_stack use variable length array
* configure.ac (HAVE_VLA): Add check. * src/misc.c (_gcry_burn_stack) [HAVE_VLA]: Add VLA code. -- Some gcc versions convert _gcry_burn_stack into loop that overwrites the same 64-byte stack buffer instead of burn stack deeper. It's argued at GCC bugzilla that _gcry_burn_stack is doing wrong thing here [1] and that this kind of optimization is allowed. So lets fix _gcry_burn_stack by using variable length array when VLAs are supported by compiler. This should ensure proper stack burning to the requested depth and avoid GCC loop optimizations. [1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52285 Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'src/misc.c')
-rw-r--r--src/misc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 2d9c73aa..135aeb4c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -290,13 +290,20 @@ _gcry_log_printhex (const char *text, const void *buffer, size_t length)
void
_gcry_burn_stack (int bytes)
{
- char buf[64];
+#ifdef HAVE_VLA
+ int buflen = (((bytes <= 0) ? 1 : bytes) + 63) & ~63;
+ volatile char buf[buflen];
+
+ wipememory (buf, sizeof buf);
+#else
+ volatile char buf[64];
wipememory (buf, sizeof buf);
bytes -= sizeof buf;
if (bytes > 0)
_gcry_burn_stack (bytes);
+#endif
}
void