Skip to content

Commit

Permalink
use Address Sanitizer for tests. Fix small issues
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanHri committed Nov 5, 2023
1 parent 5463440 commit 0b20a0c
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ EXTENDED_CFLAGS += -Wconversion
EXTENDED_CFLAGS += -Wpedantic
#EXTENDED_CFLAGS += -Werror

#Clang warning flahs
#Clang warning flags
else ifeq ($(findstring clang,$(CC)),clang)
EXTENDED_CFLAGS += -Wcast-qual
EXTENDED_CFLAGS += -Wconversion
Expand All @@ -144,9 +144,9 @@ endif

# use AddressSanitizer to find memory bugs
# comment this out for better speed
#EXTENDED_CFLAGS += -fsanitize=address -fno-omit-frame-pointer
#CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
#LDFLAGS += -fsanitize=address -static-libasan
EXTENDED_CFLAGS += -fsanitize=address -fomit-frame-pointer
CXXFLAGS += -fsanitize=address -fomit-frame-pointer
LDFLAGS += -fsanitize=address -static-libasan

$(info EXTENDED_CFLAGS are $(EXTENDED_CFLAGS))
################################################################################
Expand Down
3 changes: 2 additions & 1 deletion inc/common/byte_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ enum err byte_array_cpy(struct byte_array *dest, const struct byte_array *src,
*/
#ifdef VLA
#define BYTE_ARRAY_NEW(NAME, BUF_SIZE, SIZE) \
if (SIZE <= 0) { \
if (SIZE < 0) { \
return vla_insufficient_size; \
} \
uint8_t NAME##_buf[SIZE]; \
struct byte_array NAME = BYTE_ARRAY_INIT(NAME##_buf, SIZE);

#else
#define BYTE_ARRAY_NEW(NAME, BUF_SIZE, SIZE) \
TRY(check_buffer_size(BUF_SIZE, SIZE)); \
Expand Down
4 changes: 2 additions & 2 deletions samples/linux_edhoc/responder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ USOCORE_UEDHOC_BUILD_PATH = $(USOCORE_UEDHOC_PATH)build

ifeq ($(ARCH_32_ONLY), 1)
# build for 32 bit x68
# export the varible so that it is availbale in the uoscore-uedhoc Makefile
# export the variable so that it is available in the uoscore-uedhoc Makefile
ARCH = -m32
export ARCH
endif
Expand All @@ -47,7 +47,7 @@ CPP_SOURCES += src/main.cpp
CPP_SOURCES += ../../../externals/cantcoap/cantcoap.cpp

# C sources
# rename files avaible with the same name in diferent libraries
# rename files available with the same name in different libraries
# todo clean up this
$(shell mv ../../../externals/compact25519/src/c25519/sha512.c ../../../externals/compact25519/src/c25519/_sha512.c )
$(shell mv ../../../externals/tinycrypt/lib/source/sha256.c ../../../externals/tinycrypt/lib/source/tc_sha256.c )
Expand Down
44 changes: 34 additions & 10 deletions samples/linux_oscore/server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# in order to rebuild the uoscore-uedhoc.a and server application call:
# make oscore_edhoc; make

include ../../../makefile_config.mk

# toolchain
CXX = g++
CC = gcc
SZ = size
MAKE = make
CXX ?= g++
CC ?= gcc
SZ ?= size
MAKE ?= make

# target
TARGET = server
Expand All @@ -27,7 +29,7 @@ USOCORE_UEDHOC_PATH = ../../../
USOCORE_UEDHOC_BUILD_PATH = $(USOCORE_UEDHOC_PATH)build

# build for 32 bit x68
# export the varible so that it is availbale in the uoscore-uedhoc Makefile
# export the variable so that it is available in the uoscore-uedhoc Makefile
ARCH = -m32
export ARCH

Expand All @@ -42,29 +44,50 @@ CPP_SOURCES += src/main.cpp
CPP_SOURCES += ../../../externals/cantcoap/cantcoap.cpp

# C sources
# rename files avaible with the same name in diferent libraries
# todo clean up this
# rename files available with the same name in different libraries
$(shell mv ../../../externals/compact25519/src/c25519/sha512.c ../../../externals/compact25519/src/c25519/_sha512.c )

C_SOURCES += src/_entropy.c
C_SOURCES += $(wildcard ../../common/*.c)
C_SOURCES += $(wildcard ../../../externals/zcbor/src/*.c)
C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c)

# Crypto engine dependent source files
ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519)
C_SOURCES += $(wildcard ../../../externals/compact25519/src/c25519/*.c)
C_SOURCES += $(wildcard ../../../externals/compact25519/src/*.c)
endif

ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT)
C_SOURCES += $(wildcard ../../../externals/tinycrypt/lib/source/*.c)
endif

ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS)
C_SOURCES += $(wildcard ../../../externals/mbedtls/library/*.c)
endif

# C includes
C_INCLUDES += -I../../../inc/
C_INCLUDES += -I../../common/
C_INCLUDES += -I../../../test_vectors/
C_INCLUDES += -I../../../externals/cantcoap/
C_INCLUDES += -I../../../externals/zcbor/include

# Crypto engine dependent includes
ifeq ($(findstring COMPACT25519,$(CRYPTO_ENGINE)),COMPACT25519)
C_INCLUDES += -I../../../externals/compact25519/src/c25519/
C_INCLUDES += -I../../../externals/compact25519/src/
endif

ifeq ($(findstring TINYCRYPT,$(CRYPTO_ENGINE)),TINYCRYPT)
C_INCLUDES += -I../../../externals/tinycrypt/lib/include
endif

ifeq ($(findstring MBEDTLS,$(CRYPTO_ENGINE)),MBEDTLS)
C_INCLUDES += -I../../../externals/mbedtls/library
C_INCLUDES += -I../../../externals/mbedtls/include
C_INCLUDES += -I../../../externals/mbedtls/include/mbedtls
C_INCLUDES += -I../../../externals/mbedtls/include/psa
C_INCLUDES += -I../../../externals/compact25519/src/
C_INCLUDES += -I../../../externals/compact25519/src/c25519
endif

# C defines
# make PRINT_ARRAY macro usable in the main file
Expand All @@ -76,6 +99,7 @@ LD_LIBRARY_PATH += -L$(USOCORE_UEDHOC_BUILD_PATH)

LDFLAGS += $(LD_LIBRARY_PATH)
LDFLAGS += -luoscore-uedhoc
LDFLAGS += -lstdc++
LDFLAGS += $(ARCH)
##########################################
# CFLAGS
Expand Down
1 change: 0 additions & 1 deletion src/edhoc/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ static enum err ca_pk_get(const struct cred_array *cred_array,

PRINT_ARRAY("cred_array[i].ca.ptr", cred_array->ptr[i].ca.ptr,
cred_array->ptr[i].ca.len);
PRINT_ARRAY("issuer", issuer, cred_array->ptr[i].ca.len);

mbedtls_x509_crt m_cert;
mbedtls_x509_crt_init(&m_cert);
Expand Down
2 changes: 1 addition & 1 deletion src/oscore/oscore_coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ enum err options_deserialize(struct byte_array *in_data,
/* Update parameters*/
i = (uint16_t)(i + temp_option_header_len + temp_option_len);
temp_options_ptr += temp_option_len;
if (MAX_OPTION_COUNT > temp_options_count) {
if ((MAX_OPTION_COUNT - 1) > temp_options_count) {
temp_options_count++;
} else {
return too_many_options;
Expand Down
11 changes: 10 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})

project(auto_test)

target_compile_options(app PRIVATE -fsanitize=address -fomit-frame-pointer)

FILE(GLOB app_sources
*.c
edhoc_integration_tests/*.c
Expand Down Expand Up @@ -41,8 +43,15 @@ zephyr_get_system_include_directories_for_lang_as_string(C system_includes)
zephyr_get_compile_definitions_for_lang_as_string(C definitions)
zephyr_get_compile_options_for_lang_as_string(C options)

#message("C includes is: ${includes}")
#message("C system_includes is: ${system_includes}")
#message("C definitions is: ${definitions}")
#message("C options is: ${options}")

# To provide flags with west use COMMAND_LINE_FLAGS, e.g.:
# west build -b native_posix -- -DCOMMAND_LINE_FLAGS="-DVLA"
set(external_project_cflags
"${includes} ${definitions} ${options} ${system_includes}"
"${COMMAND_LINE_FLAGS} ${includes} ${definitions} ${options} ${system_includes}"
)

include(ExternalProject)
Expand Down
2 changes: 1 addition & 1 deletion test/edhoc_integration_tests/edhoc_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void test_exporter(void);
* results with pre computed values.
* @param vec_num the test vector number
*/
void test_initiator_responder_interaction(uint8_t vec_num);
void test_initiator_responder_interaction(int vec_num);

void t_initiator_responder_interaction1();
void t_initiator_responder_interaction2();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ void thread_initiator(void *vec_num, void *dummy2, void *dummy3)
ARG_UNUSED(dummy3);

PRINT_MSG("Initiator thread started!\n");
int vec_num_i = *((int *)vec_num) - 1;

uint8_t vec_num_i = *((int *)vec_num) - 1;
enum err r;

struct other_party_cred cred_r;
Expand Down Expand Up @@ -251,7 +251,7 @@ void thread_responder(void *vec_num, void *dummy2, void *dummy3)

PRINT_MSG("Responder thread started!\n");
enum err r;
uint8_t vec_num_i = *((int *)vec_num) - 1;
int vec_num_i = *((int *)vec_num) - 1;

/* test vector inputs */
struct other_party_cred cred_i;
Expand Down Expand Up @@ -334,7 +334,7 @@ void thread_responder(void *vec_num, void *dummy2, void *dummy3)
PRINTF("An error has occurred. Error code: %d\n", r);
}

void test_initiator_responder_interaction(uint8_t vec_num)
void test_initiator_responder_interaction(int vec_num)
{
PRINT_MSG("start initiator_responder_interaction\n");

Expand Down
2 changes: 1 addition & 1 deletion test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

// in order to execute only a specific tes set this macro to a specific
// test macro and comment out EXECUTE_ALL_TESTS
#define EXECUTE_ONLY_TEST TEST_EDHOC_EXPORTER
#define EXECUTE_ONLY_TEST T10_OSCORE_CLIENT_SERVER_AFTER_REBOOT

/**
* @brief This function allows to skip a given test if only one other test
Expand Down
8 changes: 4 additions & 4 deletions test/oscore_integration_tests/oscore_integration_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,10 @@ void t10_oscore_client_server_after_reboot(void)
0x9B, 0x7B, 0x1C, 0x90, 0x37, 0x9E,
0x83, 0x93, 0x4B };

/**************************************************************************/
/* 1) |------request----------------------------->| */
/* |<-----response with ECHO option (ECHO1)----| */
/**************************************************************************/
/**********************************************************************/
/*1) |------request----------------------------->| */
/* |<-----response with ECHO option (ECHO1)----| */
/**********************************************************************/
/*
*
* First request
Expand Down
2 changes: 2 additions & 0 deletions test/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ CONFIG_ZTEST=y
CONFIG_ZTEST_STACK_SIZE=120000
CONFIG_INIT_STACKS=y

# use Address SAnitizer
CONFIG_ASAN=y

# enable to use thread names
CONFIG_THREAD_NAME=y
Expand Down

0 comments on commit 0b20a0c

Please sign in to comment.