From d781d0d6edd532380c5600ba2fdf6279318a958d Mon Sep 17 00:00:00 2001 From: Kris Kwiatkowski Date: Sat, 9 Feb 2019 00:59:13 +0000 Subject: [PATCH] enable undefined behaviour sanitizer --- Makefile | 2 +- test/crypto_sign/functest.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a99e7a90..791962aa 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ endif bin/sanitizer_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme mkdir -p bin - $(CC) $(CFLAGS) -fsanitize=address \ + $(CC) $(CFLAGS) -fsanitize=address,undefined \ -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \ -iquote "./common/" \ -iquote "$(SCHEME)/clean/" \ diff --git a/test/crypto_sign/functest.c b/test/crypto_sign/functest.c index edd484c9..b13a19ae 100644 --- a/test/crypto_sign/functest.c +++ b/test/crypto_sign/functest.c @@ -6,15 +6,17 @@ #define NTESTS 15 #define MLEN 32 +typedef uint64_t unaligned_uint64_t __attribute__((aligned(1))); + /* allocate a bit more for all keys and messages and * make sure it is not touched by the implementations. */ static void write_canary(unsigned char *d) { - *((uint64_t *)d) = 0x0123456789ABCDEF; + *((unaligned_uint64_t *)d) = 0x0123456789ABCDEF; } static int check_canary(const unsigned char *d) { - if (*(uint64_t *)d != 0x0123456789ABCDEF) { + if (*(unaligned_uint64_t *)d != 0x0123456789ABCDEF) { return -1; }