为什么 AddressSanitizer 没有在 nginx 中显示堆 use-after-free 错误
2021-8-29 10:53:10
收藏:0
阅读:144
评论:0
我有如下的测试代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
struct Info {
char *p;
int num;
};
int main()
{
struct Info *pInfo = (struct Info*)malloc(sizeof(struct Info));
free(pInfo);
printf("%d\n", pInfo->num);
return 0;
}
我使用以下命令编译和执行它:
gcc -O1 -g -fsanitize=address test.c -o t
AddressSanitizer 可以打印错误信息,例如 heap-use-after-free,如下所示:
==15552==ERROR: AddressSanitizer: heap-use-after-free on address 0x60200000eff8 at pc 0x47b4a1 bp 0x7fff17684ed0 sp 0x7fff17684ec8
READ of size 4 at 0x60200000eff8 thread T0
#0 0x47b4a0 in main /home/xiabaichuan/test_tmp/test.c:18
#1 0x7f318a01a554 in __libc_start_main (/lib64/libc.so.6+0x22554)
#2 0x47b38c in _start (/home/xiabaichuan/test_tmp/t+0x47b38c)
0x60200000eff8 is located 8 bytes inside of 16-byte region [0x60200000eff0,0x60200000f000)
freed by thread T0 here:
#0 0x465129 in free (/home/xiabaichuan/test_tmp/t+0x465129)
#1 0x47b465 in main /home/xiabaichuan/test_tmp/test.c:17
previously allocated by thread T0 here:
#0 0x4652a9 in __interceptor_malloc (/home/xiabaichuan/test_tmp/t+0x4652a9)
#1 0x47b45a in main /home/xiabaichuan/test_tmp/test.c:16
SUMMARY: AddressSanitizer: heap-use-after-free /home/xiabaichuan/test_tmp/test.c:18 main
Shadow bytes around the buggy address:
然而,当我将相同的测试代码复制到 nginx http 模块中,编译并运行后,发送 HTTP 请求来触发代码后,AddressSanitizer 没有输出任何堆 use-after-free 错误信息;编译 NGINX 的命令如下:
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
当我发送 HTTP 请求到 nginx 时,printf 打印出一个随机数,但是 AddressSanitizer 没有输出任何错误信息;nginx 打印如下内容:
[root@osboxes sbin]# ./nginx
788529154 (提示:这个数字是一个随机错误数字)
nginx 测试代码如下:
struct Info
{
int num;
};
static void
ngx_http_flv_live_cleanup(void *data)
{
ngx_rtmp_session_t *s;
s = data;
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
"live:\"flv close connection\"");
struct Info *pInfo = (struct Info *)malloc(sizeof(struct Info));
pInfo->num = 2;
free(pInfo);
ngx_http_flv_live_close_session_handler(s);
ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
"live:\"flv close connection:%d\"", pInfo->num);
printf("%d\n", pInfo->num);
ngx_http_flv_live_close_session_handler(s);
}
当我使用 curl 访问 flv-http URL 时,这段代码可能会被执行,但是这段代码:“printf("%d\n", pInfo->num);”不会显示堆 use-after-free,只会打印一个随机数。
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
- 如何编写 Lua 模式将字符串(嵌套数组)转换为真正的数组?