0

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

Francesco
  • 897
  • 8
  • 22
  • You'll need to sift through the "3000 lines long" log file, figure out why the configure script failed, and figure out what to do about it. There's only a small chance that someone else on stackoverflow.com tried exactly the same thing you did, and ran into the exact same problem, and knows what the solution is. Otherwise, you are the only one who can look at the file and see what happened. The error will be towards to the end of config.log. Look on the bright side: once you learn how to track down this kind of a failure, you won't need to ask anyone else for help on this, ever again. – Sam Varshavchik Dec 29 '20 at 19:23
  • `/lib/cpp` seems to me like a strange place to have the C preprocessor. Are you sure that even is the C preprocessor? Maybe your environment is messed up. – john Dec 29 '20 at 19:23
  • @SamVarshavchik updated – Francesco Dec 29 '20 at 19:38
  • @john I agree, I think it's because of the impossibility of ImageMagick to check the `afl-g++` version: – Francesco Dec 29 '20 at 19:39
  • 1
    So, `afl-g++` does not seem to implement `--version` parameter, it seems. What I would do next is have a shell script wrapper for `afl-g++` that itself checks for `--version` and emits what configure expects, and otherwise execute the real `afl-g++`. I would also notify `afl-g++`'s developers about this oversight, sounds to me something they'll surely want to fix. An alternative workaround would be to run `configure` as is, but then to override `CC` and `CXX` when running `make`. – Sam Varshavchik Dec 29 '20 at 20:17

2 Answers2

0

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.

dv3
  • 4,369
  • 5
  • 28
  • 50
0

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.

Francesco
  • 897
  • 8
  • 22