Fix UBSAN error
Some checks failed
ci / build_and_test (Debug, macos-latest) (push) Has been cancelled
ci / build_and_test (Debug, ubuntu-22.04) (push) Has been cancelled
ci / build_and_test (Debug, ubuntu-24.04) (push) Has been cancelled
ci / build_and_test (Debug, windows-latest) (push) Has been cancelled
ci / build_and_test (Release, macos-latest) (push) Has been cancelled
ci / build_and_test (Release, ubuntu-22.04) (push) Has been cancelled
ci / build_and_test (Release, ubuntu-24.04) (push) Has been cancelled
ci / build_and_test (Release, windows-latest) (push) Has been cancelled
ci / windows-arm64 (push) Has been cancelled
ci / android (arm64-v8a) (push) Has been cancelled
ci / android (armeabi-v7a) (push) Has been cancelled
ci / reuse (push) Has been cancelled
ci / chromium (push) Has been cancelled
ci / generate_source (push) Has been cancelled
format / clang-format (push) Has been cancelled

Calling memcpy with either src or dst as nullptr is undefined
even if the count is 0.

Discovered by running tests with -fsanitize=undefined

safe_struct.extension_add_remove specifcially
This commit is contained in:
jpr42 2025-04-11 23:20:56 -07:00 committed by Charles Giessen
parent ad2ffcba7b
commit 4ee0833a3c
2 changed files with 19 additions and 2 deletions

View file

@ -25,6 +25,22 @@ add_subdirectory(scripts)
find_package(VulkanHeaders CONFIG)
option(VUL_ENABLE_ASAN "Use address sanitization")
if (VUL_ENABLE_ASAN)
add_compile_options(-fsanitize=address)
if (NOT MSVC)
add_link_options(-fsanitize=address)
endif()
endif()
option(VUL_ENABLE_UBSAN "Use undefined behavior sanitization")
if (VUL_ENABLE_UBSAN)
if (NOT MSVC)
add_compile_options(-fsanitize=undefined)
add_link_options(-fsanitize=undefined)
endif()
endif()
add_subdirectory(src)
add_subdirectory(include)
@ -37,7 +53,6 @@ if (PROJECT_IS_TOP_LEVEL)
endif()
option(VUL_ENABLE_INSTALL "Enable install" ${PROJECT_IS_TOP_LEVEL})
if (VUL_ENABLE_INSTALL)
include(GNUInstallDirs)

View file

@ -83,7 +83,9 @@ bool AddExtension(CreateInfo& ci, const char* extension_name) {
return false;
}
char** exts = new char*[ci.enabledExtensionCount + 1];
memcpy(exts, ci.ppEnabledExtensionNames, sizeof(char*) * ci.enabledExtensionCount);
if (ci.ppEnabledExtensionNames) {
memcpy(exts, ci.ppEnabledExtensionNames, sizeof(char*) * ci.enabledExtensionCount);
}
exts[ci.enabledExtensionCount] = SafeStringCopy(extension_name);
delete[] ci.ppEnabledExtensionNames;
ci.ppEnabledExtensionNames = exts;