1
1
mirror of https://github.com/henrydcase/pqc.git synced 2024-11-22 23:48:58 +00:00

enable undefined behaviour sanitizer (#19)

enable undefined behaviour sanitizer
This commit is contained in:
Douglas Stebila 2019-02-10 16:02:51 -05:00 committed by GitHub
commit 522826a090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -43,7 +43,7 @@ endif
bin/sanitizer_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme bin/sanitizer_$(subst /,_,$(SCHEME)): test/$(dir $(SCHEME))functest.c $(wildcard $(SCHEME)/clean/*.c) $(wildcard $(SCHEME)/clean/*.h) | require_scheme
mkdir -p bin 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) \ -DPQCLEAN_NAMESPACE=$(shell echo PQCLEAN_$(subst -,,$(notdir $(SCHEME))) | tr a-z A-Z) \
-iquote "./common/" \ -iquote "./common/" \
-iquote "$(SCHEME)/clean/" \ -iquote "$(SCHEME)/clean/" \

View File

@ -6,15 +6,17 @@
#define NTESTS 15 #define NTESTS 15
#define MLEN 32 #define MLEN 32
typedef uint64_t unaligned_uint64_t __attribute__((aligned(1)));
/* allocate a bit more for all keys and messages and /* allocate a bit more for all keys and messages and
* make sure it is not touched by the implementations. * make sure it is not touched by the implementations.
*/ */
static void write_canary(unsigned char *d) { static void write_canary(unsigned char *d) {
*((uint64_t *)d) = 0x0123456789ABCDEF; *((unaligned_uint64_t *)d) = 0x0123456789ABCDEF;
} }
static int check_canary(const unsigned char *d) { static int check_canary(const unsigned char *d) {
if (*(uint64_t *)d != 0x0123456789ABCDEF) { if (*(unaligned_uint64_t *)d != 0x0123456789ABCDEF) {
return -1; return -1;
} }