validator occur coredump in centos 7
zengjinji opened this issue · 4 comments
zengjinji commented
Environmental :
centos7
kernel: 3.10.0-862.14.4.el7.x86_64
gdb
(gdb) bt
#0 0x00007fa1ad141caa in __memcpy_ssse3_back () from /lib64/libc.so.6
#1 0x00007fa1aa9e8193 in rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8<char>, void>, rapidjson::CrtAllocator>::AddErrorLocation (
this=this@entry=0x18044a0, result=..., parent=<optimized out>) at /tmp/lua-rapidjson/rapidjson/include/rapidjson/schema.h:2338
#2 0x00007fa1aa9e8982 in rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8<char>, void>, rapidjson::CrtAllocator>::AddCurrentError (
this=0x18044a0, keyword=..., parent=<optimized out>) at /tmp/lua-rapidjson/rapidjson/include/rapidjson/schema.h:2362
#3 0x00007fa1aa9e8f75 in rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8<char>, void>, rapidjson::CrtAllocator>::EndDisallowedType (
this=0x18044a0, actualType=...) at /tmp/lua-rapidjson/rapidjson/include/rapidjson/schema.h:2027
#4 0x00007fa1aa9eb418 in StartObject (context=..., this=0x1802ee0) at /tmp/lua-rapidjson/rapidjson/include/rapidjson/schema.h:873
#5 rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8<char>, void>, rapidjson::CrtAllocator>::StartObject (this=this@entry=0x18044a0)
at /tmp/lua-rapidjson/rapidjson/include/rapidjson/schema.h:2114
#6 0x00007fa1aa9ede48 in rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::Accept<rapidjson::GenericSchemaValidator<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>, rapidjson::BaseReaderHandler<rapidjson::UTF8<char>, void>, rapidjson::CrtAllocator> > (this=0x1802ee0, handler=...)
at /tmp/lua-rapidjson/rapidjson/include/rapidjson/document.h:1869
#7 0x00007fa1aa9dee73 in SchemaValidator_validate (L=0x7fa1aec82df0) at /tmp/lua-rapidjson/src/Schema.cpp:97
#8 0x00007fa1ae211caa in lj_BC_FUNCC () from /tmp/openresty/luajit/lib/libluajit-5.1.so.2
#9 0x00000000004d8669 in ngx_http_lua_run_thread (L=L@entry=0x7fa1aecbc378, r=r@entry=0x18fa040, ctx=ctx@entry=0x18fad10, nrets=nrets@entry=0)
at ../ngx_lua-0.10.15/src/ngx_http_lua_util.c:1091
#10 0x00000000004db71a in ngx_http_lua_content_by_chunk (L=0x7fa1aecbc378, r=0x18fa040) at ../ngx_lua-0.10.15/src/ngx_http_lua_contentby.c:122
#11 0x00000000004db2ac in ngx_http_lua_content_handler (r=0x18fa040) at ../ngx_lua-0.10.15/src/ngx_http_lua_contentby.c:224
#12 0x00000000004587be in ngx_http_core_content_phase (r=0x18fa040, ph=<optimized out>) at src/http/ngx_http_core_module.c:1180
#13 0x0000000000453355 in ngx_http_core_run_phases (r=0x18fa040) at src/http/ngx_http_core_module.c:869
#14 0x000000000045e021 in ngx_http_process_request_headers (rev=rev@entry=0x17d3580) at src/http/ngx_http_request.c:1381
#15 0x000000000045e374 in ngx_http_process_request_line (rev=0x17d3580) at src/http/ngx_http_request.c:1051
coredump reproduce
cd /tmp;
wget https://openresty.org/download/openresty-1.15.8.1.tar.gz
tar -zxvf openresty-1.15.8.1.tar.gz
cd openresty-1.15.8.1/
./configure --prefix=/tmp/openresty
gmake install
yum install -y cmake3
cd /tmp;
git clone https://github.com/xpol/lua-rapidjson.git;
cd lua-rapidjson/
LUA_DIR=/tmp/openresty/luajit/ cmake3 -H. -Bbuild
cmake3 --build build --config Release
cp build/rapidjson.so /tmp/openresty/lualib/
git clone https://gist.github.com/49f3bd3c7a9d96a988d484bf8b996323.git
cd 49f3bd3c7a9d96a988d484bf8b996323/
cp test_json.lua /tmp/openresty/lualib/
cp nginx.conf /tmp/openresty/nginx/conf/
/tmp/openresty/nginx/sbin/nginx -c /tmp/openresty/nginx/conf/nginx.conf
cd path/wrk
./wrk -d 60 -t 2 -c 100 http://localhost:8990/2
tailf /tmp/openresty/nginx/logs/error.log
zengjinji commented
i am not good at c++, could you help see it?
membphis commented
please take a look at this: https://github.com/iresty/apisix/blob/master/lua/apisix/core/schema.lua#L18
it works fine at my side.
zengjinji commented
I see it and changed my way of using it. it can not occur coredump, thanks a lot ! @membphis
zengjinji commented
But I still don't understand why occur coredump.
According to my understanding, occur coredump means code has bug. If it doesn't work correctly, it need to return the error instead of occur coredump
using like it, it work well
function _M.content()
local waf_sd = rapidjson.SchemaDocument(waf_checker)
local waf_validator = rapidjson.SchemaValidator(waf_sd)
local t = rapidjson.decode(str);
local d = rapidjson.Document(t)
waf_validator:validate(d)
end
but using like it, it occur coredump in centos7 and work find in centos6, I do this because I just want to initialize SchemaValidator once
local waf_sd = rapidjson.SchemaDocument(waf_checker)
local waf_validator = rapidjson.SchemaValidator(waf_sd)
function _M.content()
local t = rapidjson.decode(str);
local d = rapidjson.Document(t)
waf_validator:validate(d)
end