From b649b98cb54e5f8a6ecb53787728c4f09572046a Mon Sep 17 00:00:00 2001 From: Nikolaj Schlej Date: Tue, 31 Jan 2023 17:45:29 -0800 Subject: [PATCH] Add support for Clang sanitizers for UEFITool Only applied to CMake Debug builds, useful for debugging undefined behavior. --- .github/workflows/main.yml | 11 ++++++----- CMakeLists.txt | 2 +- UEFITool/CMakeLists.txt | 20 +++++++++++++++++++- UEFITool/uefitool.cpp | 2 +- common/utility.cpp | 4 ++-- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index aa6e24d..5c6345a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,7 +39,7 @@ jobs: - name: Upload to releases if: github.event_name == 'release' - uses: svenstaro/upload-release-action@e74ff71f7d8a4c4745b560a485cc5fdb9b5b999d + uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: dist/*.zip @@ -68,7 +68,7 @@ jobs: - name: Upload to releases if: github.event_name == 'release' - uses: svenstaro/upload-release-action@e74ff71f7d8a4c4745b560a485cc5fdb9b5b999d + uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: dist/*.zip @@ -116,7 +116,7 @@ jobs: - name: Upload to releases if: github.event_name == 'release' - uses: svenstaro/upload-release-action@e74ff71f7d8a4c4745b560a485cc5fdb9b5b999d + uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: dist/*.zip @@ -215,7 +215,7 @@ jobs: - name: Upload to releases if: github.event_name == 'release' - uses: svenstaro/upload-release-action@e74ff71f7d8a4c4745b560a485cc5fdb9b5b999d + uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} file: dist/*.zip @@ -344,8 +344,9 @@ jobs: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - name: Set up JDK 11 - uses: actions/setup-java@v1 + uses: actions/setup-java@v3 with: + distribution: 'zulu' java-version: 11 - name: Download and set up sonar-scanner diff --git a/CMakeLists.txt b/CMakeLists.txt index 71e7a1c..eae7c2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.16) +CMAKE_MINIMUM_REQUIRED(VERSION 3.22) PROJECT(UEFITool_everything) diff --git a/UEFITool/CMakeLists.txt b/UEFITool/CMakeLists.txt index 2ee226d..8bb1d4b 100644 --- a/UEFITool/CMakeLists.txt +++ b/UEFITool/CMakeLists.txt @@ -1,4 +1,4 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 3.16) +CMAKE_MINIMUM_REQUIRED(VERSION 3.22) PROJECT(UEFITool LANGUAGES C CXX) @@ -8,6 +8,24 @@ SET(CMAKE_CXX_EXTENSIONS OFF) FIND_PACKAGE(Qt6 REQUIRED COMPONENTS Widgets) +IF (CMAKE_CXX_COMPILER_ID MATCHES "Clang") +# Enable sanitizers for debug builds done by Clang + IF(CMAKE_BUILD_TYPE MATCHES Debug) + MESSAGE("-- Clang sanitizers enabled") + ADD_COMPILE_OPTIONS(-fsanitize=undefined) + ADD_COMPILE_OPTIONS(-fsanitize=integer) + ADD_COMPILE_OPTIONS(-fsanitize=nullability) + ADD_COMPILE_OPTIONS(-fsanitize=implicit-conversion) + ADD_COMPILE_OPTIONS(-fsanitize=array-bounds) + ADD_COMPILE_OPTIONS(-fno-omit-frame-pointer) + ADD_LINK_OPTIONS(-fsanitize=integer) + ADD_LINK_OPTIONS(-fsanitize=nullability) + ADD_LINK_OPTIONS(-fsanitize=implicit-conversion) + ADD_LINK_OPTIONS(-fsanitize=array-bounds) + ADD_LINK_OPTIONS(-fno-omit-frame-pointer) + ENDIF() +ENDIF() + SET(PROJECT_FORMS uefitool.ui searchdialog.ui diff --git a/UEFITool/uefitool.cpp b/UEFITool/uefitool.cpp index 3f180a6..80524f1 100644 --- a/UEFITool/uefitool.cpp +++ b/UEFITool/uefitool.cpp @@ -580,7 +580,7 @@ void UEFITool::remove() void UEFITool::about() { QMessageBox::about(this, tr("About UEFITool"), - tr("Copyright (c) 2013-2022, Nikolaj Schlej.

" + tr("Copyright (c) 2013-2023, Nikolaj Schlej.

" "Program icon made by Alexander Zhidkov.

" "GUI uses QHexEdit2 library made by Simsys.
" "Qt-less engine uses Bstrlib made by Paul Hsieh.
" diff --git a/common/utility.cpp b/common/utility.cpp index e14258a..fcd37a7 100755 --- a/common/utility.cpp +++ b/common/utility.cpp @@ -472,7 +472,7 @@ INTN findPattern(const UINT8 *pattern, const UINT8 *patternMask, UINTN patternSi bool matches = true; for (UINTN i = 0; i < patternSize; i++) { if ((data[dataOff + i] & patternMask[i]) != pattern[i]) { - matches = true; + matches = false; break; } } @@ -583,4 +583,4 @@ USTATUS zlibDecompress(const UByteArray& input, UByteArray& output) inflateEnd(&stream); return ret == Z_STREAM_END ? U_SUCCESS : U_ZLIB_DECOMPRESSION_FAILED; -} \ No newline at end of file +}