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

974 Views Asked by At

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 <[email protected]>

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 <[email protected]>

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

2

There are 2 best solutions below

0
Francesco On BEST ANSWER

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.

3
dv3 On

Are you restricted to using afl's gcc? If not, use their clang wrapper:

I'm able to start AFL like this:

git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.0.10
cd ImageMagick-7.0.10

CC=afl-clang CXX=afl-clang++ ./configure --disable-shared
make

#prepare AFL environment
AFL_SKIP_CPU_FREQ=1 AFL_I_DONT_CARE_ABOUT_MISSING_CRASHES=1 afl-fuzz -i ./in -o ./out -- ./utilities/magick @@ /dev/null

Obviously it only rarely makes sense to start AFL like this - I'm just saying I was able to quickly start it that way.