+2024-05-09 Bruno Haible <bruno@clisp.org>
+
+ explicit_bzero, memset_explicit tests: Avoid test failures with ASAN.
+ * tests/test-explicit_bzero.c (test_heap, test_stack): Define to empty
+ if ASAN is enabled.
+ * tests/test-memset_explicit.c (test_heap, test_stack): Likewise.
+
2024-05-09 Bruno Haible <bruno@clisp.org>
dprintf-posix, fprintf-posix tests: Avoid test failures with ASAN.
/* Test of explicit_bzero() function.
- Copyright (C) 2020-2023 Free Software Foundation, Inc.
+ Copyright (C) 2020-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* =============== Verify operation on heap-allocated memory =============== */
+/* Skip this part when an address sanitizer is in use, because it would report
+ a "heap use after free". */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+static void
+test_heap (void)
+{
+}
+
+#else
+
/* Test whether an address range is mapped in memory. */
-#if VMA_ITERATE_SUPPORTED
+# if VMA_ITERATE_SUPPORTED
struct locals
{
return l.range_start == l.range_end;
}
-#else
+# else
static bool
is_range_mapped (uintptr_t range_start, uintptr_t range_end)
return true;
}
-#endif
+# endif
static void
test_heap (void)
printf ("test_heap: address range is unmapped after free().\n");
}
+#endif /* ! address sanitizer enabled */
+
/* =============== Verify operation on stack-allocated memory =============== */
+/* Skip this part when an address sanitizer is in use, because it would report
+ a "stack use after return". */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+static void
+test_stack (void)
+{
+}
+
+#else
+
/* There are two passes:
1. Put a secret in memory and invoke explicit_bzero on it.
2. Verify that the memory has been erased.
does not eliminate a call to explicit_bzero, even if data flow analysis
reveals that the stack area is dead at the end of the function. */
static bool _GL_ATTRIBUTE_NOINLINE
-#if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
+# if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
__attribute__ ((__noclone__))
-#endif
-#if __GNUC__ >= 8
+# endif
+# if __GNUC__ >= 8
__attribute__ ((__noipa__))
-#endif
+# endif
do_secret_stuff (int volatile pass, char *volatile *volatile last_stackbuf)
{
char stackbuf[SECRET_SIZE];
ASSERT (count < 50);
}
+#endif /* ! address sanitizer enabled */
+
/* ========================================================================== */
int
/* Test memset_explicit.
- Copyright 2020-2023 Free Software Foundation, Inc.
+ Copyright 2020-2024 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* =============== Verify operation on heap-allocated memory =============== */
+/* Skip this part when an address sanitizer is in use, because it would report
+ a "heap use after free". */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+static void
+test_heap (void)
+{
+}
+
+#else
+
/* Test whether an address range is mapped in memory. */
-#if VMA_ITERATE_SUPPORTED
+# if VMA_ITERATE_SUPPORTED
struct locals
{
return l.range_start == l.range_end;
}
-#else
+# else
static bool
is_range_mapped (uintptr_t range_start, uintptr_t range_end)
return true;
}
-#endif
+# endif
static void
test_heap (void)
printf ("test_heap: address range is unmapped after free().\n");
}
+#endif /* ! address sanitizer enabled */
+
/* =============== Verify operation on stack-allocated memory =============== */
+/* Skip this part when an address sanitizer is in use, because it would report
+ a "stack use after return". */
+#ifndef __has_feature
+# define __has_feature(a) 0
+#endif
+#if defined __SANITIZE_ADDRESS__ || __has_feature (address_sanitizer)
+
+static void
+test_stack (void)
+{
+}
+
+#else
+
/* There are two passes:
1. Put a secret in memory and invoke memset_explicit on it.
2. Verify that the memory has been erased.
does not eliminate a call to memset_explicit, even if data flow analysis
reveals that the stack area is dead at the end of the function. */
static bool _GL_ATTRIBUTE_NOINLINE
-#if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
+# if __GNUC__ + (__GNUC_MINOR__ >= 5) > 4
__attribute__ ((__noclone__))
-#endif
-#if __GNUC__ >= 8
+# endif
+# if __GNUC__ >= 8
__attribute__ ((__noipa__))
-#endif
+# endif
do_secret_stuff (int volatile pass, char *volatile *volatile last_stackbuf)
{
char stackbuf[SECRET_SIZE];
ASSERT (count < 50);
}
+#endif /* ! address sanitizer enabled */
+
/* ========================================================================== */
int