Skip to content

FRR with Address Sanitizer

Quentin Young edited this page Mar 30, 2018 · 3 revisions

Address Sanitizer is another tool similar to Valgrind to find memory corruption, leaks, buffer overflows etc. See Address Sanitizer Homepage for more details

Building FRR with Address Sanitizer - 4.1 and Later

Pass --enable-address-sanitizer to ./configure. You are done.

Building FRR with Address Sanitizer - 4.0 and Prior

This is tested with GCC on Ubuntu 16.04, but should work on most other distributions. Make sure to have a recent GCC version to get the latest features for Address Sanitizer

  1. ./bootstrap.sh (as normal)

  2. Define some extra flags for build

     export CC=gcc
     export CFLAGS="-O1 -g -fsanitize=address -fno-omit-frame-pointer"
     export LD=gcc
     export LDFLAGS="-g -fsanitize=address -ldl"
    
  3. Run configure with your required options and disable shared images --enable-shared=no

     ./configure --enable-shared=no <and your other options>
    
  4. (Newer FRR with clippy - if lib/clippy.c exists): Build clippy without Address Sanitizer:

     make -C lib CFLAGS="-g -O2" LDFLAGS="-g" clippy
    
  5. make and make install as usual

  6. (Optional) To verify the address sanitizer build, check the binaries with ldd and look for libasan.so

Running with Address Sanitizer

By default, if there are any memory corruption, buffer overflows etc detected, then Address Sanitized will abort the program and output a detailed error to stderr. Memory Leaks will not cause an abort, but will be reported when the program ends normally. (Hint: Do a kill or killall with normal SIGTERM of the daemons at the end)

Most daemons are designed to run in the background and the output to stderr is lost. To force Address Sanitizer to write to a file instead, start the daemons with extra options:

ASAN_OPTIONS=log_path=/tmp/asan.zebra /usr/local/sbin/zebra -d
(and similar for other daemons)

This will force the output to a file named /tmp/asan.zebra. instead of stderr

For other Options, run any of the daemons [after compiling with address sanitizer] with

ASAN_OPTIONS=help=1 /usr/local/sbin/zebra
Clone this wiki locally