From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladislav Shpilevoy Subject: [PATCH 1/5] session: forbid creation from Lua binary and applier sessions Date: Mon, 19 Mar 2018 16:34:48 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com, Vladislav Shpilevoy List-ID: Lua has no access to applier or binary sockets, and these session types must be forbidden. And after #2667 applier, binary, console and background session owners will be incapsulated inside corresponding modules. Signed-off-by: Vladislav Shpilevoy --- src/box/lua/session.c | 10 ++++++++-- test/box-tap/session.test.lua | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/box/lua/session.c b/src/box/lua/session.c index ad1c6cc25..d8e91bf1f 100644 --- a/src/box/lua/session.c +++ b/src/box/lua/session.c @@ -48,6 +48,13 @@ static const char *sessionlib_name = "box.session"; static int lbox_session_create(struct lua_State *L) { + enum session_type type = + STR2ENUM(session_type, luaL_optstring(L, 2, "console")); + if (type != SESSION_TYPE_CONSOLE && type != SESSION_TYPE_REPL && + type != SESSION_TYPE_BACKGROUND) { + return luaL_error(L, "Can not start non-console or non-REPL "\ + "session from Lua"); + } struct session *session = fiber_get_session(fiber()); if (session == NULL) { int fd = luaL_optinteger(L, 1, -1); @@ -56,8 +63,7 @@ lbox_session_create(struct lua_State *L) return luaT_error(L); } /* If a session already exists, simply reset its type */ - session->type = STR2ENUM(session_type, luaL_optstring(L, 2, "console")); - + session->type = type; lua_pushnumber(L, session->id); return 1; } diff --git a/test/box-tap/session.test.lua b/test/box-tap/session.test.lua index 6fddced3c..ff952fd45 100755 --- a/test/box-tap/session.test.lua +++ b/test/box-tap/session.test.lua @@ -15,14 +15,22 @@ session = box.session space = box.schema.space.create('tweedledum') index = space:create_index('primary', { type = 'hash' }) -test:plan(53) +test:plan(55) + +-- +-- Check that can start from Lua only either console or REPL. +-- +local ok, err = pcall(box.internal.session.create, 100, "binary") +test:is(err, "Can not start non-console or non-REPL session from Lua", "bad session type") +ok, err = pcall(box.internal.session.create, 100, "applier") +test:is(err, "Can not start non-console or non-REPL session from Lua", "bad session type") --- --- Check that Tarantool creates ADMIN session for #! script --- test:ok(session.exists(session.id()), "session is created") test:isnil(session.peer(session.id()), "session.peer") -local ok, err = pcall(session.exists) +ok, err = pcall(session.exists) test:is(err, "session.exists(sid): bad arguments", "exists bad args #1") ok, err = pcall(session.exists, 1, 2, 3) test:is(err, "session.exists(sid): bad arguments", "exists bad args #2") -- 2.14.3 (Apple Git-98)