From b9a3a73c27e178f8f2ac8c7b46f6cf612c968cdc Mon Sep 17 00:00:00 2001 From: Christian Reitter Date: Wed, 12 Jan 2022 16:08:19 +0100 Subject: [PATCH] feat(crypto): improved clang version checks, remove duplicate, adapt to refactor Makefiles do not natively support compiler version checks, so some shell-based tricks have to be used instead. The ethereum_address_checksum() function changed, adapt input length. --- crypto/Makefile | 28 +++++++++++++++++++++++----- crypto/fuzzer/fuzzer.c | 2 +- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crypto/Makefile b/crypto/Makefile index 81e24e5b9..baf6deda9 100644 --- a/crypto/Makefile +++ b/crypto/Makefile @@ -1,15 +1,33 @@ +# CLANG_VERSION is empty if the compiler is not clang-based +CLANG_VERSION = $(shell $(CC) --version | grep -Po "clang version \K[\d\.]+") +CLANG_VERSION_MAJOR = $(shell echo $(CLANG_VERSION) | cut -f1 -d.) + +# determine specific version ranges +ifneq ($(CLANG_VERSION),) +$(if $(shell [ $(CLANG_VERSION_MAJOR) -ge 13 ] && echo "OK"), \ + $(eval CLANG_AT_LEAST_13 := true), \ + $(eval CLANG_AT_LEAST_13 := false)) +$(if $(shell [ $(CLANG_VERSION_MAJOR) -ge 14 ] && echo "OK"), \ + $(eval CLANG_AT_LEAST_14 := true), \ + $(eval CLANG_AT_LEAST_14 := false)) +endif + ifeq ($(FUZZER),1) CC ?= clang LD ?= $(CC) SANFLAGS += -fsanitize=fuzzer -# TODO gcc as well as older clang versions <= 12 do not support this feature +# only clang versions >= 13 support this feature +ifeq ($(CLANG_AT_LEAST_13),true) $(info "info: using -fsanitize-ignorelist") -SANFLAGS += -fsanitize-ignorelist=fuzzer/sanitizer_ignorelist.txt +SANFLAGS += -fsanitize-ignorelist=fuzzer/sanitizer_ignorelist.txt +else +$(info "info: not using -fsanitize-ignorelist") +endif # TODO is there a better solution, for example by disabling a specific optimization technique? # there is a clang optimization issue in relation with the blake2 code at -fsanitize=undefined -$(warning "warning: disable optimization on blake2 code as workaround") +$(warning "warning: disabling optimization on blake2 code as workaround") blake2b.o: OPTFLAGS += -O0 blake2s.o: OPTFLAGS += -O0 @@ -61,8 +79,8 @@ ZKP_PATH = ../vendor/secp256k1-zkp CFLAGS += -DSECP256K1_CONTEXT_SIZE=208 # TODO remove this workaround once possible -ifeq ($(CC),clang-14) -$(warning "warning: suppress clang-14 compiler warning for secp256k1-zkp code") +ifeq ($(CLANG_AT_LEAST_14),true) +$(warning "warning: suppressing clang-14 compiler warning for secp256k1-zkp code") ZKP_CFLAGS += -Wno-bitwise-instead-of-logical endif diff --git a/crypto/fuzzer/fuzzer.c b/crypto/fuzzer/fuzzer.c index f16f4b313..2764c596c 100644 --- a/crypto/fuzzer/fuzzer.c +++ b/crypto/fuzzer/fuzzer.c @@ -716,7 +716,7 @@ int fuzz_mnemonic_to_seed(void) { int fuzz_ethereum_address_checksum(void) { uint8_t addr[20] = {0}; - char address[41] = {0}; + char address[43] = {0}; uint64_t chain_id = 0; bool rskip60 = false;