From 61de6855b4390a1f45548981ccd446bfe5933d5d Mon Sep 17 00:00:00 2001 From: Chris Mc Date: Fri, 1 Dec 2023 12:06:11 -0500 Subject: [PATCH] Add a test for ubsan with C++20 (#315) * add test to ubsan with cxx 20 * Add hard error + more checks https://gcc.gnu.org/onlinedocs/gcc-6.3.0/gcc/Instrumentation-Options.html https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind https://interrupt.memfault.com/blog/ubsan-trap --------- Co-authored-by: Christopher McArthur --- .github/workflows/jwt.yml | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/jwt.yml b/.github/workflows/jwt.yml index 6dde9aabf..04ab7070d 100644 --- a/.github/workflows/jwt.yml +++ b/.github/workflows/jwt.yml @@ -63,16 +63,42 @@ jobs: run: | mkdir build cd build - cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" \ - -DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -g" \ - -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \ - -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" + cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" \ + -DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -g" \ + -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \ + -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" - name: run working-directory: build run: | make - export ASAN_OPTIONS=fast_unwind_on_malloc=0 + export ASAN_OPTIONS=check_initialization_order=true:detect_stack_use_after_return=true:fast_unwind_on_malloc=0 + ./example/rsa-create + ./example/rsa-verify + ./tests/jwt-cpp-test + + ubsan: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + - uses: ./.github/actions/install/gtest + + - name: configure + run: | + mkdir build + cd build + cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_STANDARD=20 \ + -DCMAKE_CXX_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \ + -DCMAKE_C_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all -g" \ + -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all" \ + -DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=undefined -fsanitize=return -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize-recover=all" + + - name: run + working-directory: build + run: | + make + export UBSAN_OPTIONS=print_stacktrace=1 ./example/rsa-create ./example/rsa-verify ./tests/jwt-cpp-test