<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi!<div class=""><br class=""></div><div class="">Thanks for the patch!</div><div class=""><br class=""></div><div class="">It’s strange, but Tarantool happens to handle this case correctly?</div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">% echo 'error({}); print(42)' | ./src/tarantool -e 'debug.debug()' </span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">lua_debug> (null)</span></div></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">lua_debug> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ffffff; background-color: #000000" class=""><b class="">%</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                                                                                                                                                                                                              % echo $?</span></div></div><div class=""><div>0</div></div></blockquote><div class=""><div><br class=""></div><div>Surely, with the patch applied I see the following, as expected:</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">% echo 'error({}); print(42)' | ./src/tarantool -e 'debug.debug()'</span></div></div></div><div class=""><div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">lua_debug> (error object is not a string)</span></div></div></div><div class=""><div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">lua_debug> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ffffff; background-color: #000000" class=""><b class="">%</b></span><span style="font-variant-ligatures: no-common-ligatures" class="">                                                                                                                                                                                                                                                              % </span></div></div></div></blockquote><div class=""><div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div></div><div><br class=""></div><div>Is it relevant at all?</div><div><br class=""></div><div>regards,</div><div>Sergos</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class="">On 30 Dec 2021, at 14:45, Sergey Kaplun <<a href="mailto:skaplun@tarantool.org" class="">skaplun@tarantool.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">From: Mike Pall <mike><br class=""><br class="">(cherry picked from f5b0fff5a990004375ad43aa6e6c4a11a8b6eb7e)<br class=""><br class="">`lua_tostring()` returns NULL for non-string and non-number objects.<br class="">Returned value is passed to `fputs()` without check, so that leads to<br class="">crash in case of NULL.<br class=""><br class="">This patch adds the corresponding check. "(error object is not a<br class="">string)" is returned in the aforementioned case.<br class=""><br class="">Sergey Kaplun:<br class="">* added the description and the test for the problem<br class=""><br class="">Part of tarantool/tarantool#6548<br class="">---<br class=""><br class="">Related issue: <a href="https://github.com/tarantool/tarantool/issues/6548" class="">https://github.com/tarantool/tarantool/issues/6548</a><br class="">Branch: <a href="https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-debug-debug-non-string-err" class="">https://github.com/tarantool/luajit/tree/skaplun/gh-noticket-debug-debug-non-string-err</a><br class="">Tarantool branch: <a href="https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-debug-debug-non-string-err-full-ci" class="">https://github.com/tarantool/tarantool/tree/skaplun/gh-noticket-debug-debug-non-string-err-full-ci</a><br class=""><br class=""> src/lib_debug.c                               |  3 ++-<br class=""> .../debug-non-string-error.test.lua           | 26 +++++++++++++++++++<br class=""> 2 files changed, 28 insertions(+), 1 deletion(-)<br class=""> create mode 100644 test/tarantool-tests/debug-non-string-error.test.lua<br class=""><br class="">diff --git a/src/lib_debug.c b/src/lib_debug.c<br class="">index 8fdfda03..c8f61a43 100644<br class="">--- a/src/lib_debug.c<br class="">+++ b/src/lib_debug.c<br class="">@@ -369,7 +369,8 @@ LJLIB_CF(debug_debug)<br class="">       return 0;<br class="">     if (luaL_loadbuffer(L, buffer, strlen(buffer), "=(debug command)") ||<br class=""> <span class="Apple-tab-span" style="white-space:pre">   </span>lua_pcall(L, 0, 0, 0)) {<br class="">-      fputs(lua_tostring(L, -1), stderr);<br class="">+      const char *s = lua_tostring(L, -1);<br class="">+      fputs(s ? s : "(error object is not a string)", stderr);<br class="">       fputs("\n", stderr);<br class="">     }<br class="">     lua_settop(L, 0);  /* remove eventual returns */<br class="">diff --git a/test/tarantool-tests/debug-non-string-error.test.lua b/test/tarantool-tests/debug-non-string-error.test.lua<br class="">new file mode 100644<br class="">index 00000000..9151dd1a<br class="">--- /dev/null<br class="">+++ b/test/tarantool-tests/debug-non-string-error.test.lua<br class="">@@ -0,0 +1,26 @@<br class="">+local tap = require('tap')<br class="">+<br class="">+local test = tap.test('debug-non-string-error')<br class="">+test:plan(1)<br class="">+<br class="">+local i = 0<br class="">+while arg[i] do i = i - 1 end<br class="">+local luabin = arg[i + 1]<br class="">+<br class="">+local magic = 42<br class="">+-- XXX: Need \n before print to be interpreted as independend<br class="">+-- command.<br class="">+local cmd = ([[<br class="">+  echo 'error({});<br class="">+  print(%d)' | %s -e 'debug.debug()' 2>&1<br class="">+]]):format(magic, luabin)<br class="">+<br class="">+local proc = io.popen(cmd)<br class="">+local res = proc:read('*all'):gsub('%s+$', '')<br class="">+local ldb = 'lua_debug> '<br class="">+local errmsg = '(error object is not a string)'<br class="">+-- XXX: lines aren't broken by '\n', so need 2 `ldb`.<br class="">+local expected = ldb .. errmsg .. '\n' .. ldb .. ldb .. magic<br class="">+test:ok(res == expected, 'handle non-string error in debug.debug()')<br class="">+<br class="">+os.exit(test:check() and 0 or 1)<br class="">-- <br class="">2.34.1<br class=""><br class=""></div></div></blockquote></div><br class=""></div></body></html>