为什么AddressSanitizer在nginx中不起作用
我有一个这样的测试代码为什么AddressSanitizer在nginx中不起作用,nginx,gcc,Nginx,Gcc,我有一个这样的测试代码 struct Info { int num; }; int main() { //json_object *obj; //json_object_get_string_len((obj)); struct Info *pInfo = (struct Info *)malloc(sizeof(struct Info)); pInfo->num = 2; free(pInfo); pInfo = NULL;
struct Info
{
int num;
};
int main()
{
//json_object *obj;
//json_object_get_string_len((obj));
struct Info *pInfo = (struct Info *)malloc(sizeof(struct Info));
pInfo->num = 2;
free(pInfo);
pInfo = NULL;
int num = pInfo->num;
printf("%d\n", pInfo->num);
return 0;
}
我使用cmd“gcc-g test.c-ljson-c-o t-fsanitize=address-static libasan-fno omit frame pointer”编译它,AddressSanitizer可以输出错误信息,如下所示:
==750==ERROR: AddressSanitizer: heap-use-after-free on address 0x602000000010 at pc 0x00000040092c bp 0x7fff1acf09a0 sp 0x7fff1acf0990
READ of size 4 at 0x602000000010 thread T0
#0 0x40092b in main /home/xiabaichuan/test.c:18
#1 0x7f7963386554 in __libc_start_main (/lib64/libc.so.6+0x22554)
#2 0x4007e8 (/home/xiabaichuan/t+0x4007e8)
但当我在nginx http模块中复制相同的测试代码,编译并运行时,在发送http请求触发代码后,AddressSanitarizer没有输出任何错误信息,我编译nginx cmd如下:
gcc -o objs/nginx -L/home/xiabaichuan/master/cluster_live/TOOL/openresty-1.15.8.1/build/luajit-root/usr/local/openresty/luajit/lib -L/home/xiabaichuan/master/cluster_live/TOOL/openresty-1.15.8.1/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -fsanitize=address -fno-omit-frame-pointer -fsanitize-recover=address -Wl,-E -Wl,-E -ldl -lcrypt -L/home/xiabaichuan/master/cluster_live/TOOL/openresty-1.15.8.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -L/home/xiabaichuan/master/cluster_live/TOOL/openresty-1.15.8.1/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl -lpcre -lssl -lcrypto -ldl -lz \
-Wl,-E
当我向nginx发送HTTP请求时,nginx printf会显示一个随机num,但AddressSanitizer不会输出任何错误消息,nginx打印如下:
[root@osboxes sbin]# ./nginx
788529154 (this num is a random error num)
我的gcc版本是:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr --mandir=/opt/rh/devtoolset-8/root/usr/share/man --infodir=/opt/rh/devtoolset-8/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)