diff --git a/cmake/OS_Detection.cmake b/cmake/OS_Detection.cmake index f0ea578a90987b955e70864a38d7f2f5c7f2f1c3..51bc3a0bc7b07c5f5710d910ad761ac11ea6b431 100644 --- a/cmake/OS_Detection.cmake +++ b/cmake/OS_Detection.cmake @@ -102,6 +102,11 @@ if(UNIX) if(DAP_DEBUG) set(_CCOPT "-DDAP_DEBUG ${CFLAGS_WARNINGS} -pg -g3 -ggdb -fno-eliminate-unused-debug-symbols -fno-strict-aliasing") set(_LOPT "-pg") + if (DEFINED ENV{DAP_ASAN}) + message("[!] Address Sanitizer enabled") + set(_CCOPT "${_CCOPT} -fsanitize=address -fno-omit-frame-pointer -fno-common -O1") + set(_LOPT "${_LOPT} -fsanitize=address") + endif() SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg") else() set(_CCOPT "${CFLAGS_WARNINGS} -O3 -fPIC -fno-strict-aliasing -fno-ident -ffast-math -ftree-vectorize -fno-asynchronous-unwind-tables -ffunction-sections -Wl,--gc-sections -std=gnu11") diff --git a/modules/type/dag/dap_chain_cs_dag.c b/modules/type/dag/dap_chain_cs_dag.c index dc5a5215d5b6b9a6c41b2fadf6fefb24312c9507..734cef02a670e9cbc08a3afc9f11de8ddd431cd0 100644 --- a/modules/type/dag/dap_chain_cs_dag.c +++ b/modules/type/dag/dap_chain_cs_dag.c @@ -763,13 +763,15 @@ static bool s_event_verify_size(dap_chain_cs_dag_event_t *a_event, size_t a_even return false; if (a_event->header.signs_count > UINT8_MAX) return false; - for (int i = 0; i < a_event->header.signs_count; i++) { - dap_sign_t *l_sign = (dap_sign_t *)((uint8_t *)a_event + l_sign_offset); + uint8_t i; + for (i = 0; i < a_event->header.signs_count && l_sign_offset < a_event_size; ++i) { + dap_sign_t *l_sign = (dap_sign_t*)((uint8_t*)a_event + l_sign_offset); l_sign_offset += dap_sign_get_size(l_sign); - if (l_sign_offset > a_event_size) { - log_it(L_ERROR, "%d of atom signes don't fit in the atom size %zd", a_event->header.signs_count, a_event_size); - return false; - } + } + if (i != a_event->header.signs_count) { + log_it(L_WARNING, "Malformed event! Only %d of claimed %d signs fit data size%s", + i, a_event->header.signs_count, l_sign_offset == a_event_size ? "" : ", incomplete sequence"); + } return l_sign_offset == a_event_size; }