From: sergos via Tarantool-patches <tarantool-patches@dev.tarantool.org>
To: Sergey Kaplun <skaplun@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH luajit] Fix debug.debug() for non-string errors.
Date: Tue, 21 Jun 2022 15:01:46 +0300 [thread overview]
Message-ID: <4E9E5823-C595-4F01-AA26-62D2BEA2DA28@tarantool.org> (raw)
In-Reply-To: <20211230114513.23020-1-skaplun@tarantool.org>
[-- Attachment #1: Type: text/plain, Size: 3814 bytes --]
Hi!
Thanks for the patch!
It’s strange, but Tarantool happens to handle this case correctly?
% echo 'error({}); print(42)' | ./src/tarantool -e 'debug.debug()'
lua_debug> (null)
lua_debug> % % echo $?
0
Surely, with the patch applied I see the following, as expected:
% echo 'error({}); print(42)' | ./src/tarantool -e 'debug.debug()'
lua_debug> (error object is not a string)
lua_debug> % %
Is it relevant at all?
regards,
Sergos
> On 30 Dec 2021, at 14:45, Sergey Kaplun <skaplun@tarantool.org> wrote:
>
> From: Mike Pall <mike>
>
> (cherry picked from f5b0fff5a990004375ad43aa6e6c4a11a8b6eb7e)
>
> `lua_tostring()` returns NULL for non-string and non-number objects.
> Returned value is passed to `fputs()` without check, so that leads to
> crash in case of NULL.
>
> This patch adds the corresponding check. "(error object is not a
> string)" is returned in the aforementioned case.
>
> Sergey Kaplun:
> * added the description and the test for the problem
>
> Part of tarantool/tarantool#6548
> ---
>
> Related issue: https://github.com/tarantool/tarantool/issues/6548
> Branch: https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-debug-debug-non-string-err
> Tarantool branch: https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-debug-debug-non-string-err-full-ci
>
> src/lib_debug.c | 3 ++-
> .../debug-non-string-error.test.lua | 26 +++++++++++++++++++
> 2 files changed, 28 insertions(+), 1 deletion(-)
> create mode 100644 test/tarantool-tests/debug-non-string-error.test.lua
>
> diff --git a/src/lib_debug.c b/src/lib_debug.c
> index 8fdfda03..c8f61a43 100644
> --- a/src/lib_debug.c
> +++ b/src/lib_debug.c
> @@ -369,7 +369,8 @@ LJLIB_CF(debug_debug)
> return 0;
> if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||
> lua_pcall(L, 0, 0, 0)) {
> - fputs(lua_tostring(L, -1), stderr);
> + const char *s = lua_tostring(L, -1);
> + fputs(s ? s : "(error object is not a string)", stderr);
> fputs("\n", stderr);
> }
> lua_settop(L, 0); /* remove eventual returns */
> diff --git a/test/tarantool-tests/debug-non-string-error.test.lua b/test/tarantool-tests/debug-non-string-error.test.lua
> new file mode 100644
> index 00000000..9151dd1a
> --- /dev/null
> +++ b/test/tarantool-tests/debug-non-string-error.test.lua
> @@ -0,0 +1,26 @@
> +local tap = require('tap')
> +
> +local test = tap.test('debug-non-string-error')
> +test:plan(1)
> +
> +local i = 0
> +while arg[i] do i = i - 1 end
> +local luabin = arg[i + 1]
> +
> +local magic = 42
> +-- XXX: Need \n before print to be interpreted as independend
> +-- command.
> +local cmd = ([[
> + echo 'error({});
> + print(%d)' | %s -e 'debug.debug()' 2>&1
> +]]):format(magic, luabin)
> +
> +local proc = io.popen(cmd)
> +local res = proc:read('*all'):gsub('%s+$', '')
> +local ldb = 'lua_debug> '
> +local errmsg = '(error object is not a string)'
> +-- XXX: lines aren't broken by '\n', so need 2 `ldb`.
> +local expected = ldb .. errmsg .. '\n' .. ldb .. ldb .. magic
> +test:ok(res == expected, 'handle non-string error in debug.debug()')
> +
> +os.exit(test:check() and 0 or 1)
> --
> 2.34.1
>
[-- Attachment #2: Type: text/html, Size: 9318 bytes --]
next prev parent reply other threads:[~2022-06-21 12:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-30 11:45 Sergey Kaplun via Tarantool-patches
2022-06-21 12:01 ` sergos via Tarantool-patches [this message]
2022-06-22 8:24 ` Sergey Kaplun via Tarantool-patches
2022-06-28 23:05 ` Igor Munkin via Tarantool-patches
2022-06-30 12:10 ` Igor Munkin via Tarantool-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E9E5823-C595-4F01-AA26-62D2BEA2DA28@tarantool.org \
--to=tarantool-patches@dev.tarantool.org \
--cc=sergos@tarantool.org \
--cc=skaplun@tarantool.org \
--subject='Re: [Tarantool-patches] [PATCH luajit] Fix debug.debug() for non-string errors.' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox