Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#390] Add UBSAN #369

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,41 @@ if (IRODS_ENABLE_ADDRESS_SANITIZER)
# detect_container_overflow is disabled to guard against false positives which occur when
# parts of the binary are compiled with ASAN and other parts are not.
add_compile_definitions(IRODS_ADDRESS_SANITIZER_DEFAULT_OPTIONS="log_path=/tmp/irods_client_http_api_asan_output:detect_container_overflow=0")
add_compile_options(-fsanitize=address)
add_link_options(-fsanitize=address)
endif()

option(IRODS_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER "Enables detection of undefined behavior provided by Undefined Behavior Sanitizer." OFF)
if (IRODS_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER)
# Make sure the correct llvm-symbolizer binary is available to Undefined Behavior Sanitizer. This binary
# allows debug symbols to be reported appropriately. Additionally, set options for logging.
#
# export PATH=/opt/irods-externals/clang13.0.1-0/bin:$PATH
add_compile_definitions(IRODS_UNDEFINED_BEHAVIOR_SANITIZER_DEFAULT_OPTIONS="log_path=/tmp/irods_client_http_api_ubsan_output")

add_compile_options(
-fsanitize=undefined
-fsanitize=float-divide-by-zero
-fsanitize=unsigned-integer-overflow
-fsanitize=implicit-conversion
-fsanitize=local-bounds
-fsanitize=nullability
-fsanitize-ignorelist=${CMAKE_CURRENT_SOURCE_DIR}/ub-sanitizer-ignorelist.txt)
add_link_options(
-fsanitize=undefined
-fsanitize=float-divide-by-zero
-fsanitize=unsigned-integer-overflow
-fsanitize=implicit-conversion
-fsanitize=local-bounds
-fsanitize=nullability)
endif()

if (IRODS_ENABLE_ADDRESS_SANITIZER OR IRODS_ENABLE_UNDEFINED_BEHAVIOR_SANITIZER)
add_compile_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
add_link_options(
-fsanitize=address
-fno-omit-frame-pointer
-fno-optimize-sibling-calls
-O1)
Expand Down
8 changes: 8 additions & 0 deletions core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ extern "C" const char* __asan_default_options()
} // __asan_default_options
#endif

#if __has_feature(undefined_behavior_sanitizer)
extern "C" const char* __ubsan_default_options()
{
// See root CMakeLists.txt file for definition.
return IRODS_UNDEFINED_BEHAVIOR_SANITIZER_DEFAULT_OPTIONS;
} // __ubsan_default_options
#endif

// clang-format off
namespace beast = boost::beast; // from <boost/beast.hpp>
namespace net = boost::asio; // from <boost/asio.hpp>
Expand Down
7 changes: 7 additions & 0 deletions ub-sanitizer-ignorelist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[unsigned-integer-overflow]
src:/opt/irods-externals/boost*/include/boost/beast/http/impl/field.ipp
src:/opt/irods-externals/boost*/include/boost/beast/core/impl/string.ipp
src:/opt/irods-externals/boost*/include/boost/beast/core/detail/string.hpp

[implicit-conversion]
src:/opt/irods-externals/boost*/include/boost/asio/detail/impl/signal_set_service.ipp
Loading