From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 6FCB36ECE3; Tue, 21 Jun 2022 15:01:48 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 6FCB36ECE3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1655812908; bh=HUGxe7WxpzmDX96UzxnyAXS24LOWHW/7872dCkga3yE=; h=Date:In-Reply-To:To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=A4yQ/cIIGjTpzOcL4PtSeK/Unkc6/q4DqAdwu8DAZgdyZGlKrnGSpurRm6dW37Kn6 Yx0I+Fyb+8kCaeOJZ1lqdf9z+UpivdCZ2ky68dcodzHOfiB0Mr+ENuldwcKR3OXXqP lpVTlMw0HaPsN5Y6J6GdfLJcWbN7rzOrlsj0jKdw= Received: from smtp33.i.mail.ru (smtp33.i.mail.ru [94.100.177.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 677BE6ECE3 for ; Tue, 21 Jun 2022 15:01:47 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 677BE6ECE3 Received: by smtp33.i.mail.ru with esmtpa (envelope-from ) id 1o3cZm-0005YW-Lr; Tue, 21 Jun 2022 15:01:47 +0300 Message-Id: <4E9E5823-C595-4F01-AA26-62D2BEA2DA28@tarantool.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_AAD1298E-F8C6-4915-86B3-E7C0F25274C4" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.100.31\)) Date: Tue, 21 Jun 2022 15:01:46 +0300 In-Reply-To: <20211230114513.23020-1-skaplun@tarantool.org> To: Sergey Kaplun References: <20211230114513.23020-1-skaplun@tarantool.org> X-Mailer: Apple Mail (2.3696.100.31) X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD9B458E015651D1EC06108C81BB1C71C2ECB0A0B994430A1E5182A05F538085040F6B784AEE841C7EEE2187AB6D3C58266E1B730EE2143D133F19901721C6C5632 X-8FC586DF: 6EFBBC1D9D64D975 X-C1DE0DAB: 9604B64F49C60606AD91A466A1DEF99B296C473AB1E14218AA832D12F1E9982C7866D6147AF826D8943C0C60AE6A8B0E44456C5FD6E41EE0F972CCD2F8FE1EF1CFC4036BBF6A4EA9B11811A4A51E3B0915E2725BA614EAEA1EF972C1F679AE1C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D3414C91BA6844B96CA28A0E393FFEB73E50E9205F2DF73B6CD4589D733C6328D6E196BC2517D5570CD1D7E09C32AA3244C1976A4225636C543F10A5267CDC729823A76366E8A9DE7CAFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+ZQCdndr4HlLwe5CexqIVg== X-Mailru-Sender: 11C2EC085EDE56FA38FD4C59F7EFE407D44487E96333EC7C57D284DCEEC1973AD50A67D192A2689719381EE24192DF5555834048F03EF5D4C9A814A92B2E3B1BA4250FC3964EA4964198E0F3ECE9B5443453F38A29522196 X-Mras: OK Subject: Re: [Tarantool-patches] [PATCH luajit] Fix debug.debug() for non-string errors. X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: sergos via Tarantool-patches Reply-To: sergos Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" --Apple-Mail=_AAD1298E-F8C6-4915-86B3-E7C0F25274C4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi! Thanks for the patch! It=E2=80=99s strange, but Tarantool happens to handle this case = correctly? % echo 'error({}); print(42)' | ./src/tarantool -e 'debug.debug()'=20 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> % = = = %=20 Is it relevant at all? regards, Sergos > On 30 Dec 2021, at 14:45, Sergey Kaplun wrote: >=20 > From: Mike Pall >=20 > (cherry picked from f5b0fff5a990004375ad43aa6e6c4a11a8b6eb7e) >=20 > `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. >=20 > This patch adds the corresponding check. "(error object is not a > string)" is returned in the aforementioned case. >=20 > Sergey Kaplun: > * added the description and the test for the problem >=20 > Part of tarantool/tarantool#6548 > --- >=20 > Related issue: https://github.com/tarantool/tarantool/issues/6548 > Branch: = https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-debug-debug-n= on-string-err > Tarantool branch: = https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-debug-debu= g-non-string-err-full-ci >=20 > 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 >=20 > 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), "=3D(debug = command)") || > lua_pcall(L, 0, 0, 0)) { > - fputs(lua_tostring(L, -1), stderr); > + const char *s =3D 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 =3D require('tap') > + > +local test =3D tap.test('debug-non-string-error') > +test:plan(1) > + > +local i =3D 0 > +while arg[i] do i =3D i - 1 end > +local luabin =3D arg[i + 1] > + > +local magic =3D 42 > +-- XXX: Need \n before print to be interpreted as independend > +-- command. > +local cmd =3D ([[ > + echo 'error({}); > + print(%d)' | %s -e 'debug.debug()' 2>&1 > +]]):format(magic, luabin) > + > +local proc =3D io.popen(cmd) > +local res =3D proc:read('*all'):gsub('%s+$', '') > +local ldb =3D 'lua_debug> ' > +local errmsg =3D '(error object is not a string)' > +-- XXX: lines aren't broken by '\n', so need 2 `ldb`. > +local expected =3D ldb .. errmsg .. '\n' .. ldb .. ldb .. magic > +test:ok(res =3D=3D expected, 'handle non-string error in = debug.debug()') > + > +os.exit(test:check() and 0 or 1) > --=20 > 2.34.1 >=20 --Apple-Mail=_AAD1298E-F8C6-4915-86B3-E7C0F25274C4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Hi!

Thanks = for the patch!

It=E2=80=99s 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-de= bug-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 =             &n= bsp;           &nbs= p;     |  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), = "=3D(debug command)") ||
lua_pcall(L, 0, 0, 0)) {
-      fputs(lua_tostring(L, -1), = stderr);
+      const char *s =3D = 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 =3D require('tap')
+
+local test =3D = tap.test('debug-non-string-error')
+test:plan(1)
+
+local i =3D 0
+while arg[i] do = i =3D i - 1 end
+local luabin =3D arg[i + 1]
+
+local magic =3D 42
+-- XXX: = Need \n before print to be interpreted as independend
+-- = command.
+local cmd =3D ([[
+  echo = 'error({});
+  print(%d)' | %s -e 'debug.debug()' = 2>&1
+]]):format(magic, luabin)
+
+local proc =3D io.popen(cmd)
+local res =3D = proc:read('*all'):gsub('%s+$', '')
+local ldb =3D = 'lua_debug> '
+local errmsg =3D '(error object is not a = string)'
+-- XXX: lines aren't broken by '\n', so need 2 = `ldb`.
+local expected =3D ldb .. errmsg .. '\n' .. ldb .. = ldb .. magic
+test:ok(res =3D=3D expected, 'handle = non-string error in debug.debug()')
+
+os.exit(test:check() and 0 or 1)
--
2.34.1


= --Apple-Mail=_AAD1298E-F8C6-4915-86B3-E7C0F25274C4--