Skip to content
Snippets Groups Projects
Commit 87832820 authored by Ilya Verbin's avatar Ilya Verbin Committed by Vladimir Davydov
Browse files

box: forbid non-string types in key_def.new()

Currently if a non-string type is passed to luaT_key_def_set_part,
lua_tolstring returns null-pointer type_name, which is passed to
a string formatting function in diag_set.

Closes #5222

NO_DOC=bugfix

(cherry picked from commit 5215f3f3)
parent aa2d22e2
No related branches found
No related tags found
No related merge requests found
## bugfix/box
* Fixed a bug when `type = box.NULL` in `key_def.new()` resulted in
`type = 'unsigned'` (gh-5222).
......@@ -124,8 +124,10 @@ luaT_key_def_set_part(struct lua_State *L, struct key_part_def *part,
/* Set part->type. */
lua_pushstring(L, "type");
lua_gettable(L, -2);
if (lua_isnil(L, -1)) {
diag_set(IllegalParams, "type must not be nil");
if (!lua_isstring(L, -1)) {
diag_set(IllegalParams,
"Wrong field type: expected string, got %s",
lua_typename(L, lua_type(L, -1)));
return -1;
}
size_t type_len;
......
local t = require('luatest')
local g = t.group('gh-5222')
g.test_key_def_invalid_type = function()
local key_def = require('key_def')
t.assert_error_msg_content_equals("Wrong field type: expected string, got nil", function()
key_def.new({{field = 1, type = nil}})
end)
t.assert_error_msg_content_equals("Wrong field type: expected string, got cdata", function()
key_def.new({{field = 1, type = box.NULL}})
end)
t.assert_error_msg_content_equals("Wrong field type: expected string, got table", function()
key_def.new({{field = 1, type = {}}})
end)
t.assert_error_msg_content_equals("Wrong field type: expected string, got boolean", function()
key_def.new({{field = 1, type = true}})
end)
t.assert_error_msg_content_equals("Unknown field type: 2989", function()
key_def.new({{field = 1, type = 2989}})
end)
t.assert_error_msg_content_equals("Unknown field type: bad", function()
key_def.new({{field = 1, type = 'bad'}})
end)
t.assert_error_msg_content_equals("Unknown field type: ", function()
key_def.new({{field = 1, type = ''}})
end)
end
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