tests/unit/test_xasprintf.c: Fix use of volatile pointer
volatile needs to be casted away behind a [[gnu::noipa]] function, to make that invisible to the compiler. Otherwise, the compiler can see that it is being discarded, and is free to abuse Undefined Behavior. Closes: <https://github.com/shadow-maint/shadow/issues/1028> Reported-by: Chris Hofstaedtler <zeha@debian.org> Tested-by: Chris Hofstaedtler <zeha@debian.org> Reviewed-by: Chris Hofstaedtler <zeha@debian.org> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
3307a8f4f0
commit
6e57238bf9
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -32,6 +33,10 @@ int __real_vasprintf(char **restrict p, const char *restrict fmt, va_list ap);
|
|||||||
int __wrap_vasprintf(char **restrict p, const char *restrict fmt, va_list ap);
|
int __wrap_vasprintf(char **restrict p, const char *restrict fmt, va_list ap);
|
||||||
void __wrap_exit(int status);
|
void __wrap_exit(int status);
|
||||||
|
|
||||||
|
[[gnu::noipa]]
|
||||||
|
static int xasprintf_volatile(char *volatile *restrict s,
|
||||||
|
const char *restrict fmt, ...);
|
||||||
|
|
||||||
static void test_xasprintf_exit(void **state);
|
static void test_xasprintf_exit(void **state);
|
||||||
static void test_xasprintf_ok(void **state);
|
static void test_xasprintf_ok(void **state);
|
||||||
|
|
||||||
@@ -62,6 +67,18 @@ __wrap_exit(int status)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
xasprintf_volatile(char *volatile *restrict s, const char *restrict fmt, ...)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
len = xvasprintf((char **) s, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_xasprintf_exit(void **state)
|
test_xasprintf_exit(void **state)
|
||||||
{
|
{
|
||||||
@@ -75,7 +92,7 @@ test_xasprintf_exit(void **state)
|
|||||||
switch (setjmp(jmpb)) {
|
switch (setjmp(jmpb)) {
|
||||||
case 0:
|
case 0:
|
||||||
len = XASPRINTF_CALLED;
|
len = XASPRINTF_CALLED;
|
||||||
len = xasprintf(&p, "foo%s", "bar");
|
len = xasprintf_volatile(&p, "foo%s", "bar");
|
||||||
assert_unreachable();
|
assert_unreachable();
|
||||||
break;
|
break;
|
||||||
case EXIT_CALLED:
|
case EXIT_CALLED:
|
||||||
|
|||||||
Reference in New Issue
Block a user