Skip to content

Commit

Permalink
COMP: Suppress ubsan in H5detect.c code
Browse files Browse the repository at this point in the history
Similar to work previously done: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/4370

The H5detect.c code is used to interrogate the compiler and hardware
features.  The tests must be allowed to violate the ubsan checks
during the interrogations.

Found when compiling with:
-fsanitize=undefined -fsanitize=integer -fsanitize=nullability -fno-sanitize-recover=undefined

[14/1947] Linking C executable bin/H5detect
ITK/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5detect.c:1277:5: runtime error: store to misaligned address 0x60000211c061 for type 'short', which requires 2 byte alignment
0x60000211c061: note: pointer points here
 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ITK/Modules/ThirdParty/HDF5/src/itkhdf5/src/H5detect.c:1277:5 in
/bin/sh: line 1: 38182 Abort trap: 6           ITK/cmake-build-debug/bin/H5detect H5Tinit.c

no_sanitize_address and no_address_safety_analysis are deprecated
** use **
__attribute__((no_sanitize("address","undefined","integer","nullability"))) instead.

A more heavy handed solution may be:
__attribute__((disable_sanitizer_instrumentation)).
This attribute works similar to __attribute__((no_sanitize("address"))), but it also prevents
instrumentation performed by other sanitizers.
  • Loading branch information
hjmjohnson committed Mar 17, 2023
1 parent e7a9e9a commit bdc5234
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Modules/ThirdParty/HDF5/src/itkhdf5/src/H5detect.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ H5_GCC_DIAG_OFF("cast-align")

#if defined(__has_attribute)
#if __has_attribute(no_sanitize_address)
#define HDF_NO_UBSAN __attribute__((no_sanitize_address))
#define HDF_NO_UBSAN __attribute__((no_sanitize("address","undefined","integer","nullability")))
#else
#define HDF_NO_UBSAN
#endif
Expand Down Expand Up @@ -828,7 +828,7 @@ done:\n\
*-------------------------------------------------------------------------
*/
static void
static void HDF_NO_UBSAN
iprint(detected_t *d)
{
unsigned int pass;
Expand Down

0 comments on commit bdc5234

Please sign in to comment.