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
6
votes
0 answers

UBSan: boost::program_options with std::string

We are currently investigating a possible undefined behaviour in our program that is flagged by clang7 UBSan in combination with boost::program_option from boost 1.69.0. We have created the following working example that can we compiled and run…
nafur
  • 181
  • 4
6
votes
2 answers

C++ clang UBsan suppression flag name

Running the gzip.hpp code from boost version 1.64 with clang's ubsan gives the following message: path/to/boost/1_64_0/include/boost/iostreams/filter/gzip.hpp:674:16: runtime error: implicit conversion from type 'int' of value 139 (32-bit, signed)…
Elrond1337
  • 424
  • 1
  • 5
  • 16
6
votes
1 answer

clang: -fsanitize=undefined with 128 integer operations (undefined reference to `__muloti4')

In clang, I run into linking error if the Undefined Behavior Sanitizer (-fsanitize=undefined) when the program uses 128 bit integer. The linking errors complain about __muloti4: $ cat example.c __int128_t a; int main (void) { a = a * a; return…
Philipp Claßen
  • 41,306
  • 31
  • 146
  • 239
6
votes
1 answer

how to use ubsan on gcc (windows 8.1)

In order to have a better protection against UB cases like: #include int f(){ int x; return x; } int main() { f(); while(1); return 0; } I've updated my GCC today so I could use ubsan. My current version is 5.3.0 according…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
6
votes
3 answers

How to set ASAN/UBSAN reporting output

I would like to run my unit test suite with -fsanitize=address,undefined and have all sanitizer errors be written to a report.txt file. By default all sanitizer errors get written to stdout, however the software also writes info to stdout so this…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
6
votes
2 answers

Undefined behavior sanitizer suppression file: failed to parse suppressions

After compiling an application with clang 3.6 using -fsanitize=undefined, I'm trying to start the instrumented program while using a suppression file to ignore some of the errors: UBSAN_OPTIONS="suppressions=ubsan.supp" ./app.exe The suppression…
nucleon
  • 1,128
  • 1
  • 6
  • 19
5
votes
0 answers

Suppress specific sanitizer check, but still fail program on all others

I would like to suppress one error in a third-party library, but still have the program exit 1 on any other failed check. It seems to me that -fno-sanitize-recover will exit the program regardless of the suppressions file's contents. With…
Laurenz
  • 1,810
  • 12
  • 25
5
votes
1 answer

Understanding a runtime error triggered by the undefined behavior sanitizer (UBSan)

I find a run-time error in GNU Scientific Library (GSL) when undefined sanitizer is enabled: deque.c:58:11: runtime error: member access within misaligned address 0x0000024010f4 for type 'struct deque', which requires 8 byte…
zell
  • 9,830
  • 10
  • 62
  • 115
5
votes
1 answer

undefined reference to `__ubsan_handle_nonnull_arg'

I have been working on the problem set speller for the last days and so far this is what I have. Unfortunately, it does not compile and I am a bit lost. I would be really grateful if somebody can help me out and tell me, what I am doing wrong. //…
viet
  • 61
  • 1
  • 2
5
votes
2 answers

Clang runtime checks: print backtrace

Clang compiler provides a number of useful runtime checks, like e.g. -fsanitize=unsigned-integer-overflow. Can I print a backtrace (e.g. using gdb) when one of the checks fails? Currently I get the exact location of the problem, but I do not have…
Tomek
  • 621
  • 1
  • 6
  • 16
4
votes
0 answers

Why do the clang sanitizers not link the sanitizer runtimes when linking shared libraries

Right in the docs for the address sanitizer (https://releases.llvm.org/7.0.0/tools/clang/docs/AddressSanitizer.html), it states that: When linking shared libraries, the AddressSanitizer run-time is not linked, so -Wl,-z,defs may cause link…
acm
  • 12,183
  • 5
  • 39
  • 68
4
votes
0 answers

Clang: generated .o file incompatible with elf64-x86-64

I am trying to cross compile with clang and run Undefined Behavior Sanitizer for .c file Command I am running clang -target sparc -integrated-as -fuse-ld=lld -fsanitize=undefined test1.c clang is the cross compiler sparc is the target architecture.…
suyashsingh234
  • 189
  • 1
  • 2
  • 12
4
votes
0 answers

How to fix this C++ UBSAN vptr runtime error (runtime error: member call on address)

I enabled ubsan test (-fsanitize=undefined) in my project and found some ubsan runtime errors. Can anyone help me find why it failed here? How to fix this issue on GCC and Clang? Here is the lib.so module which includes lib.h and…
4
votes
2 answers

ld: file not found: /Library/Developer/.../libclang_rt.ubsan_osx_dynamic.dylib

I'm trying to use the Undefined Behavior Sanitizer by building like this gcc -fsanitize=undefined add.c -o add also clang -fsanitize=undefined -O add.c -o add In both cases, I'm getting a file not found error: ld: file not found:…
Leahcim
  • 40,649
  • 59
  • 195
  • 334
4
votes
0 answers

Is -fsanitize=bounds-strict included in -fsanitize=undefined for GCC 6?

I'm working on a problem report for a C++ library compiled with GCC 6. I'm reading through the GCC 6 Changes, New Features, and Fixes, and one of the notes is: UndefinedBehaviorSanitizer gained a new sanitization option, -fsanitize=bounds-strict,…
jww
  • 97,681
  • 90
  • 411
  • 885