c++imagemagickfuzzingamerican-fuzzy-lop

Why afl-g++ can't compile ImageMagick?


I'm trying to experiment some fuzz testing with the tool afl (link). I downloaded the source code of ImageMagick as described in the docs, but when I try to run ./configure with the afl compiler I get an error:

$ CC=/usr/local/bin/afl-gcc CXX=/usr/local/bin/afl-g++ ./configure --disable-shared
[...]
checking whether we are using the GNU C++ compiler... no
checking whether /usr/local/bin/afl-g++ accepts -g... no
checking dependency style of /usr/local/bin/afl-g++... none
checking how to run the C++ preprocessor... /lib/cpp
configure: error: in `/home/ubuntu/ImageMagick-7.0.10':
configure: error: C++ preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details

If I try to use the default c++ compiler everything seems fine:

$ CC=/usr/local/bin/afl-gcc ./configure --disable-shared #this works

How can I make the compiler run?

UPDATE

Looking inside config.log, the problem seems related to the impossibility of ImageMagick to check the afl-g++ version:

configure:15015: checking for C++ compiler version
configure:15024: /usr/local/bin/afl-g++ --version >&5
)B[?25h[0m[1;91m
[-] PROGRAM ABORT : [1;97mOops, failed to execute 'g++' - check your PATH[1;91m
         Location : [0mmain(), afl-gcc.c:334

configure:15035: $? = 1

Anyway, afl-g++ seems to work:

$ afl-g++
afl-cc 2.52b by <lcamtuf@google.com>

This is a helper application for afl-fuzz. It serves as a drop-in replacement
for gcc or clang, letting you recompile third-party code with the required
runtime instrumentation. A common use pattern would be one of the following:

  CC=/usr/local/bin/afl-gcc ./configure
  CXX=/usr/local/bin/afl-g++ ./configure

You can specify custom next-stage toolchain via AFL_CC, AFL_CXX, and AFL_AS.
Setting AFL_HARDEN enables hardening optimizations in the compiled code.

But afl-g++ -v reports error:

$ afl-g++ -v
afl-cc 2.52b by <lcamtuf@google.com>

[-] PROGRAM ABORT : Oops, failed to execute 'g++' - check your PATH
         Location : main(), afl-gcc.c:334


Solution

  • It turned out that the problem was the absence of g++ in my system. Probably that's because I have installed the minimal version of Ubuntu 20.04LTS. I installed g++ with

    sudo apt install g++
    

    and now everything seems to work.