Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH v2] lua: assert on lua_gettop() negative return value
@ 2020-07-21 11:05 Ilya Kosarev
  2020-07-21 11:54 ` Nikita Pettik
  2020-07-21 18:07 ` Igor Munkin
  0 siblings, 2 replies; 5+ messages in thread
From: Ilya Kosarev @ 2020-07-21 11:05 UTC (permalink / raw)
  To: imun; +Cc: tarantool-patches

In case lua_gettop() called from encode_lua_call() returns negative
value, we will segfault in iproto_reply_error() with empty diag, as far
as it is unexpected error path not covered with diagnostics. Thus
corresponding sane check with assert is introduced.

Closes #4649
---
Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-4649-sane-check-on-lua_gettop
Issue: https://github.com/tarantool/tarantool/issues/4649

Changes in v2:
- added reasoning in comment

 src/box/lua/call.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/box/lua/call.c b/src/box/lua/call.c
index ca871e077..516276a9f 100644
--- a/src/box/lua/call.c
+++ b/src/box/lua/call.c
@@ -361,6 +361,12 @@ encode_lua_call(lua_State *L)
 
 	struct luaL_serializer *cfg = luaL_msgpack_default;
 	int size = lua_gettop(port->L);
+	/*
+	 * lua_gettop() might return negative value in case the internal state
+	 * of the given Lua coroutine is seriously broken. In case of such
+	 * behavior execution has to be aborted immediately.
+	 */
+	assert(size >= 0);
 	for (int i = 1; i <= size; ++i)
 		luamp_encode(port->L, cfg, &stream, i);
 	port->size = size;
-- 
2.17.1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-21 18:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 11:05 [Tarantool-patches] [PATCH v2] lua: assert on lua_gettop() negative return value Ilya Kosarev
2020-07-21 11:54 ` Nikita Pettik
2020-07-21 12:12   ` Ilya Kosarev
2020-07-21 18:07 ` Igor Munkin
2020-07-21 18:19   ` Nikita Pettik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox