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 3B4526E1C9; Thu, 30 Dec 2021 14:47:08 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 3B4526E1C9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1640864828; bh=9IvWmt5E6OE6UGiG/tsXmfymD/W8J2AAnCSgnoyAk5Y=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=LuldDE0bmzna5biBQAoTzYSsfYWz4cQENSljzmiAkFf9irnbVZE6DkidFQ7VqEhBr mSzlwGLN9NPsR6jxwfYfLwU1JO4WphRwamL5Q8IPoN+PTGSAigh8iC/5EscqRc66ER 7mYOUQAGzjo+ql9R6YNctye230aDhxfoZFRw5b90= Received: from smtp39.i.mail.ru (smtp39.i.mail.ru [94.100.177.99]) (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 693B26E1C9 for ; Thu, 30 Dec 2021 14:47:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 693B26E1C9 Received: by smtp39.i.mail.ru with esmtpa (envelope-from ) id 1n2tti-0000vW-Gx; Thu, 30 Dec 2021 14:47:06 +0300 To: Sergey Ostanevich , Igor Munkin Date: Thu, 30 Dec 2021 14:45:13 +0300 Message-Id: <20211230114513.23020-1-skaplun@tarantool.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD94D5EF110843E6A676E515EAF4FD70AA3725BF6578192D028182A05F53808504025856D2A8B26AB3CAA6B8BC685A1F53B756ED5E47A4C796C7746794CF131A2B8 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE792C68BF9CD4C0E9EEA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637FBDDB35DE4C816078638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D8B3EF16C793BB99BE2F78371A2E3AFB6C117882F4460429724CE54428C33FAD305F5C1EE8F4F765FCF1175FABE1C0F9B6A471835C12D1D9774AD6D5ED66289B52BA9C0B312567BB23117882F446042972877693876707352033AC447995A7AD18C26CFBAC0749D213D2E47CDBA5A96583BA9C0B312567BB231DD303D21008E29813377AFFFEAFD269A417C69337E82CC2E827F84554CEF50127C277FBC8AE2E8BA83251EDC214901ED5E8D9A59859A8B6D0C9BB9AE6BD5D69089D37D7C0E48F6C5571747095F342E88FB05168BE4CE3AF X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975C98DCDA00E0158592F387C70371FC26E662D1285447152B389C2B6934AE262D3EE7EAB7254005DCED8F78043E3CC547881E0A4E2319210D9B64D260DF9561598F01A9E91200F654B0FEFB8A20A2F5DA258E8E86DC7131B365E7726E8460B7C23C X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34D9DC20663B80603FC1B4B1469A09222B85E422A2EAA21D29ED4C4646659FB93EA9A2F07D5364367A1D7E09C32AA3244C7341A1628A6FA34D0AA1D974AF65E1AAF26BFA4C8A6946B8927AC6DF5659F194 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj1qmHCAeuKqPoj5Zq5t+SHg== X-Mailru-Sender: 3B9A0136629DC91206CBC582EFEF4CB4E0160BC128F7EE9CF904FECE39D818AF871496219147EAC9F2400F607609286E924004A7DEC283833C7120B22964430C52B393F8C72A41A84198E0F3ECE9B5443453F38A29522196 X-Mras: Ok Subject: [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: Sergey Kaplun via Tarantool-patches Reply-To: Sergey Kaplun Cc: tarantool-patches@dev.tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall (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