mirror of
https://github.com/shadow-maint/shadow.git
synced 2026-01-26 22:12:26 +00:00
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> Cherry-picked-from: 6e57238bf915 ("tests/unit/test_xasprintf.c: Fix use of volatile pointer") Cc: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
parent
d5616f4c4e
commit
babbfd2ffb
@ -5,6 +5,7 @@
|
||||
|
||||
|
||||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.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);
|
||||
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_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
|
||||
test_xasprintf_exit(void **state)
|
||||
{
|
||||
@ -75,7 +92,7 @@ test_xasprintf_exit(void **state)
|
||||
switch (setjmp(jmpb)) {
|
||||
case 0:
|
||||
len = XASPRINTF_CALLED;
|
||||
len = xasprintf(&p, "foo%s", "bar");
|
||||
len = xasprintf_volatile(&p, "foo%s", "bar");
|
||||
assert_unreachable();
|
||||
break;
|
||||
case EXIT_CALLED:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user