【问题标题】:Why afl-g++ can't compile ImageMagick?为什么 afl-g++ 无法编译 ImageMagick?
【发布时间】:2020-12-29 19:19:16
【问题描述】:

我正在尝试使用 afl (link) 工具进行一些模糊测试。我下载了 ImageMagick as described in the docs 的源代码,但是当我尝试使用 afl 编译器运行 ./configure 时出现错误:

$ 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

如果我尝试使用默认的 c++ 编译器,一切似乎都很好:

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

如何让编译器运行?

更新

查看config.log 内部,问题似乎与ImageMagick 无法检查afl-g++ 版本有关:

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

无论如何,afl-g++ 似乎有效:

$ 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.

但是afl-g++ -v报错:

$ 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

【问题讨论】:

  • 您需要筛选“3000 行长”的日志文件,找出配置脚本失败的原因,并找出解决办法。 stackoverflow.com 上的其他人尝试与您所做的完全相同的事情并遇到完全相同的问题并且知道解决方案是什么的可能性很小。否则,您是唯一可以查看文件并了解发生了什么的人。错误将接近 config.log 的末尾。往好的方面看:一旦你学会了如何追查这种失败,你就不需要再向其他人寻求帮助了。
  • /lib/cpp 在我看来是一个拥有 C 预处理器的奇怪地方。你确定甚至是C预处理器吗?也许你的环境搞砸了。
  • @SamVarshavchik 已更新
  • @john 我同意,我认为这是因为 ImageMagick 无法检查 afl-g++ 版本:
  • 所以,afl-g++ 似乎没有实现--version 参数,看来。我接下来要做的是为afl-g++ 提供一个shell 脚本包装器,它本身会检查--version 并发出configure 期望的内容,否则执行真正的afl-g++。我还将通知afl-g++ 的开发人员有关此疏忽的情况,在我看来,他们肯定会想要修复。另一种解决方法是按原样运行configure,然后在运行make 时覆盖CCCXX

标签: c++ imagemagick fuzzing american-fuzzy-lop


【解决方案1】:

您是否仅限于使用 afl 的 gcc?如果没有,请使用他们的 clang 包装器:

我可以像这样开始 AFL:

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

显然,像这样开始 AFL 很少有意义 - 我只是说我能够以这种方式快速开始。

【讨论】:

  • 是的,我只能使用afl的gcc
  • 这听起来像是一个奇怪的限制,但没关系
  • 非常酷!我也给了学生类似的任务,但从不局限于 gcc。这就是我觉得奇怪的原因。
【解决方案2】:

原来问题是我的系统中没有g++。可能是因为我安装了 Ubuntu 20.04LTS 的最低版本。我用

安装了g++
sudo apt install g++

现在一切似乎都正常了。

【讨论】:

    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-26
    相关资源
    最近更新 更多