Questions tagged [ubsan]

Undefined Behavior sanitizer (ubsan) is a fast undefined behavior detector for Clang and GCC. Various computations will be instrumented to detect undefined behavior at runtime.

Undefined Behavior sanitizer (ubsan) is a fast undefined behavior detector for C and C++ programs and enabled at compile time (but the checks are performed at runtime). It is available since Clang 3.2 and GCC 4.9.

See also:

65 questions
4
votes
1 answer

Clang++ UBSAN reports invalid value fro type 'std::_Ios_Fmtflags'

The following codes will crash when they are compiled by clang UBSAN #include #include #include #include template inline std::string floatToString(T i){ printf("in floatToString\n"); …
zhanxw
  • 3,159
  • 3
  • 34
  • 32
3
votes
1 answer

How to detect ubsan presence with g++

I have some valid C++ code that does not compile under ubsan with g++. In a nutshell (https://gcc.godbolt.org/z/9qvz89na8): struct foo { void bar() { } }; void process(auto f) { if constexpr(&decltype(f)::bar); } int main() { …
Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75
3
votes
0 answers

Running santizers (ubsan, asan, etc) on python code containing C++ wrapped by pybind11

I maintain a large C++ library which I have partially exposed to python using pybind11. The C++ library contains unit test which I run sometimes under various sanitizers: asan, tsan, etc. These tests run cleanly, but of course tests aren't perfect…
Steven Scott
  • 481
  • 3
  • 14
3
votes
2 answers

What's the idiomatic way of enabling UB sanitization in CMake?

I want to build a test program for a repository of mine with undefined behavior sanitization enabled (at least with GCC and perhaps clang). I know how to do this manually: Add -fsanitize=undefined to the compilation flags Add -lubsan to the linking…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
3
votes
0 answers

Clang++ LSAN and UBSAN causes undefined reference to `__ubsan_handle_add_overflow'

When I was playing with compiler sanitizers, I was confused by this linking error when only LSAN and UBSAN are enabled on clang++. Note that the linking problem disappeared when I removed -fsanitize=leak or added these flags together:…
jerryc05
  • 454
  • 1
  • 4
  • 16
3
votes
1 answer

Load of address X with insufficient space for an object of type Y

I'm running some updates through Undefined Behavior Sanitizer. The sanitizer is producing a message I don't quite understand: kalyna.cpp:1326:61: runtime error: load of address 0x0000016262c0 with insufficient space for an object of type 'const…
jww
  • 97,681
  • 90
  • 411
  • 885
3
votes
1 answer

UBSan And Asan usage with GCC 4.9.2

I have compiled my application with -fsanitize=undefined option. How can I now test my application for undefined behavior? Also, how do I run an Asan check? I've compiled my program with -fsanitize=address, and it crashes with the following…
Ilya
  • 728
  • 2
  • 8
  • 22
2
votes
1 answer

Address sanitizer error when using boost serialization

I've recently tried to use boost serialization to serialize a class which contains a std::vector>> as a member. According to the boost documentation…
Marko Popovic
  • 3,999
  • 3
  • 22
  • 37
2
votes
2 answers

UBSAN reports: -875 << 7 as undefined behaviour

Simple code snippet: #define FOO 7 int bar = -875; bar <<= FOO; This is being reported by UBSAN as UB. My understanding is that -875 << 7 is just -(875<<7) and there is no overflow. So, is there a real problem here?
Jacko
  • 12,665
  • 18
  • 75
  • 126
2
votes
0 answers

What package do I need for Cygwin's UBsan?

I have a test script that grinds through various configurations. The script tests for the availability of Undefined Behavior sanitizer (UBsan), and then performs the build if available. Here's the test: $CXX -x c++ -dM -E -fsanitize=undefined…
jww
  • 97,681
  • 90
  • 411
  • 885
1
vote
0 answers

Strange clang c++ ubsan error when moving std::ostringstream

This might not be the correct forum to post this, as it looks like an error that I should report to the llvm team perhaps. Please let me know if you agree and I'll do just that. Here's the code that produces the ubsan error, just in case I'm…
user5406764
  • 1,627
  • 2
  • 16
  • 23
1
vote
1 answer

How to catch `abi::__forced_unwind` while keeping UBSan happy?

Like libstdc++, we're checking in some places for abi::__forced_unwind, and just re-throw it instead of taking some other action. Like libstdc++, we catch it by reference: try { /* ... */ } catch (abi::__forced_unwind&) { throw; } catch…
Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
1
vote
1 answer

Shouldn't I be warned about undefined behavior with -INT_MIN?

Consider the following C program: #include int main() { int x = INT_MIN; int y = -x; return y; } This program has undefined behavior, as the negation of INT_MIN is not representable; or, to be a language lawyer - since the C…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
1 answer

How to enable signed-integer-overflow UBSan in linux kernel?

As I was configuring the kernel 5.4.0 with: CONFIG_UBSAN=y UBSAN_SANITIZE_ALL=y and -fsanitize=signed-integer-overflow also appeared in gcc command during compilation. However, in the final vmlinux, __ubsan_handle_add_overflow was in the image, but…
Charley
  • 69
  • 1
  • 3
1
vote
1 answer

fsanitize=undefined causes linker errors

I'm trying to compile a program using -fsanitize=undefined using the conda g++ compiler. I'm running into `__ubsan_handle_type_mismatch' linker errors. I've used the flags in the compiles and the linking as suggested in: Using GCC Undefined…
NateM
  • 177
  • 1
  • 12