From ada8c97cd2a697a0d6da3a089b46a950f09c4671 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov <gorcunov@gmail.com> Date: Fri, 8 Nov 2019 16:54:16 +0300 Subject: [PATCH] box/console: fix abnormal exit after unknown command When invalid command is passed we should send an error message to a client. Instead a nil dereference occurs that causes abnormal exit of a console. This is the regression from 96dbc49d097a96af5273cce2b5663db5917f4ea9 ('box/console: Refactor command handling'). Reported-by: Mergen Imeev <imeevma@tarantool.org> Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> Reviewed-by: Alexander Turenko <alexander.turenko@tarantool.org> --- src/box/lua/console.lua | 2 +- test/app-tap/console.test.lua | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 52df674651..d4d8ec984e 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -323,7 +323,7 @@ local function preprocess(storage, line) end if items == nil then local msg = "Invalid command \\%s. Type \\help for help." - return format(false, msg:format(items[1])) + return format(false, msg:format(line)) end return operators[items[1]](storage, unpack(items)) end diff --git a/test/app-tap/console.test.lua b/test/app-tap/console.test.lua index 9e8b41b84e..da5c1e71ea 100755 --- a/test/app-tap/console.test.lua +++ b/test/app-tap/console.test.lua @@ -21,7 +21,7 @@ local EOL = "\n...\n" test = tap.test("console") -test:plan(72) +test:plan(73) -- Start console and connect to it local server = console.listen(CONSOLE_SOCKET) @@ -292,6 +292,20 @@ client:write("box.session.type();\n") test:is(yaml.decode(client:read(EOL))[1], "console", "session type") client:close() +-- +-- An unknown backslash started command causes abnormal exit of +-- a console. +-- +local cmd = '\\unknown_command' +local exp_res = {error = string.format( + 'Invalid command %s. Type \\help for help.', cmd)} +client = socket.tcp_connect("unix/", CONSOLE_SOCKET) +client:read(128) +client:write(('%s\n'):format(cmd)) +local res = yaml.decode(client:read(EOL))[1] +test:is_deeply(res, exp_res, 'unknown command') +client:close() + server:close() box.schema.user.drop('test') -- GitLab