From 33dc5d611f578ace9833a80dc006a34b09da18af Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 25 May 2018 19:35:52 -0700 Subject: fixes #484 crashes in websocket transport fixes #490 posix_epdesc use-after-free bug fixes #489 Sanitizer based testing would help fixes #492 Numerous memory leaks found with sanitizer This introduces support for compiler-based sanitizers when using clang or gcc (and not on Windows). See NNG_SANITIZER for possible settings such as "thread" or "address". Furthermore, we have fixed the issues we found with both the thread and address sanitizers. We believe that the thread issues pointed to a low frequency use-after-free responsible for rare crashes in some of the tests. The tests generally have their timeouts doubled when running under a sanitizer, to account for the extra long times that the sanitizer can cause these to take. While here, we also changed the compat_ws test to avoid a particularly painful and time consuming DNS lookup, and we made the nngcat_unlimited test a bit more robust by waiting before sending traffic. --- cmake/CheckSanitizer.cmake | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 cmake/CheckSanitizer.cmake (limited to 'cmake') diff --git a/cmake/CheckSanitizer.cmake b/cmake/CheckSanitizer.cmake new file mode 100644 index 00000000..a6b3501f --- /dev/null +++ b/cmake/CheckSanitizer.cmake @@ -0,0 +1,30 @@ +# +# Copyright 2018 Staysail Systems, Inc. +# Copyright 2017 Capitar IT Group BV +# +# This software is supplied under the terms of the MIT License, a +# copy of which should be located in the distribution where this +# file was obtained (LICENSE.txt). A copy of the license may also be +# found online at https://opensource.org/licenses/MIT. +# + +macro (CheckSanitizer) + + if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set(NNG_SAN_LIST none address leak memory thread undefined) + elseif (CMAKE_C_COMPILER_ID STREQUAL "Clang") + set(NNG_SAN_LIST none address leak memory thread undefined) + elseif (CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + set(NNG_SAN_LIST none address thread undefined) + else () + set(NNG_SAN_LIST none) + endif () + set (NNG_SANITIZER none CACHE STRING "Sanitizer to use (clang or gcc).") + set_property(CACHE NNG_SANITIZER PROPERTY STRINGS ${NNG_SAN_LIST}) + mark_as_advanced (NNG_SANITIZER) + + if (NOT NNG_SANITIZER STREQUAL "none") + set (NNG_C_FLAG_SANITIZER "-fsanitizer=${NNG_SANITIZER}") + message(STATUS "Enabling sanitizer: ${NNG_C_FLAG_SANITIZER}") + endif() +endmacro () -- cgit v1.2.3-70-g09d2