diff options
author | Bruno Haible <bruno@clisp.org> | 2021-08-29 18:54:54 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2021-08-29 19:04:36 +0200 |
commit | a55152ea2eb061403ab128cd7a63772753e83cd0 (patch) | |
tree | 96adc74f54a31519a6e86f454e40c87d8843e7fe | |
parent | 6c546529534fff50fa5afccfe772fa39174e2a6e (diff) | |
download | gnulib-a55152ea2eb061403ab128cd7a63772753e83cd0.tar.gz |
explicit_bzero test: Fix test failure due to GCC optimizations.
* tests/test-explicit_bzero.c (do_secret_stuff): Use static variable
'last_stackbuf'.
(main): Use an 'if' to combine the two do_secret_stuff invocations.
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | tests/test-explicit_bzero.c | 21 |
2 files changed, 26 insertions, 4 deletions
@@ -1,3 +1,10 @@ +2021-08-29 Bruno Haible <bruno@clisp.org> + + explicit_bzero test: Fix test failure due to GCC optimizations. + * tests/test-explicit_bzero.c (do_secret_stuff): Use static variable + 'last_stackbuf'. + (main): Use an 'if' to combine the two do_secret_stuff invocations. + 2021-08-29 Paul Eggert <eggert@cs.ucla.edu> dfa: port to non-gnulib @@ -6,6 +13,8 @@ * lib/dfa.h (_GL_ATTRIBUTE_DEALLOC) [!_GL_ATTRIBUTE_MALLOC]: Add missing definition. +2021-08-29 Paul Eggert <eggert@cs.ucla.edu> + base32, base64: fix broken tests Problem reported by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2021-08/msg00170.html diff --git a/tests/test-explicit_bzero.c b/tests/test-explicit_bzero.c index 14f0ead2b7..15a2526983 100644 --- a/tests/test-explicit_bzero.c +++ b/tests/test-explicit_bzero.c @@ -139,16 +139,22 @@ test_heap (void) static int _GL_ATTRIBUTE_NOINLINE do_secret_stuff (volatile int pass) { + static char *last_stackbuf; char stackbuf[SECRET_SIZE]; if (pass == 1) { memcpy (stackbuf, SECRET, SECRET_SIZE); explicit_bzero (stackbuf, SECRET_SIZE); + last_stackbuf = stackbuf; return 0; } else /* pass == 2 */ { - return memcmp (zero, stackbuf, SECRET_SIZE) != 0; + /* Use last_stackbuf here, because stackbuf may be allocated at a + different address than last_stackbuf. This can happen + when the compiler splits this function into different functions, + one for pass == 1 and one for pass != 1. */ + return memcmp (zero, last_stackbuf, SECRET_SIZE) != 0; } } @@ -158,10 +164,17 @@ test_stack (void) int count = 0; int repeat; - for (repeat = 1000; repeat > 0; repeat--) + for (repeat = 2 * 1000; repeat > 0; repeat--) { - do_secret_stuff (1); - count += do_secret_stuff (2); + /* This odd way of writing two consecutive statements + do_secret_stuff (1); + count += do_secret_stuff (2); + ensures that the two do_secret_stuff calls are performed with the same + stack pointer value, on m68k. */ + if ((repeat % 2) == 0) + do_secret_stuff (1); + else + count += do_secret_stuff (2); } /* If explicit_bzero works, count is near 0. (It may be > 0 if there were some asynchronous signal invocations between the two calls of |