Skip to content
Snippets Groups Projects
Commit d1c53754 authored by Ilya's avatar Ilya Committed by Roman Tsisyk
Browse files

msgpack: Fix segfault in ibuf_decode

Fix segfault in case when ibuf.rpos is null
Now error is raised in the case

Closes #3005
parent f40ab7f1
No related branches found
No related tags found
No related merge requests found
......@@ -548,6 +548,9 @@ lua_ibuf_msgpack_decode(lua_State *L)
{
uint32_t ctypeid = 0;
const char *rpos = *(const char **)luaL_checkcdata(L, 1, &ctypeid);
if (rpos == NULL) {
luaL_error(L, "msgpack.ibuf_decode: rpos is null");
}
struct luaL_serializer *cfg = luaL_checkserializer(L);
luamp_decode(L, cfg, &rpos);
*(const char **)luaL_pushcdata(L, ctypeid) = rpos;
......
......@@ -36,14 +36,17 @@ local function test_offsets(test, s)
end
local function test_misc(test, s)
test:plan(3)
test:plan(4)
local ffi = require('ffi')
local buffer = require('buffer')
local buf = ffi.cast("const char *", "\x91\x01")
local bufcopy = ffi.cast('const char *', buf)
local bufend, result = s.ibuf_decode(buf)
local st,e = pcall(s.ibuf_decode, buffer.ibuf().rpos)
test:is(buf, bufcopy, "ibuf_decode argument is constant")
test:is(buf + 2, bufend, 'ibuf_decode position')
test:is_deeply(result, {1}, "ibuf_decode result")
test:ok(not st and e:match("null"), "null ibuf")
end
tap.test("msgpack", function(test)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment