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 BCF746F70E5; Wed, 22 Nov 2023 13:55:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org BCF746F70E5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700650507; bh=SorLfIKbb8QypqE4HeOr0YT1gso9qyAg+I+ZMgQifFc=; h=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Gat0QeCGjC1ykDcCHN7YoSVnUe8WogWeItG1PO8zE2Pv1uQklka6riX1HQcwRBwX3 /MUN6ZpPOSjA5kpRp3vfSMrjcnYnGVy1o8rrC//uZAd6fuhJZVHS3GPn9DOyHXSDI6 xt/5PmxikS6Vw5ojyWKOl5dJj8T+ZeyPM47DjIXM= Received: from smtp32.i.mail.ru (smtp32.i.mail.ru [95.163.41.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 1BBBC6F70E5 for ; Wed, 22 Nov 2023 13:55:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 1BBBC6F70E5 Received: by smtp32.i.mail.ru with esmtpa (envelope-from ) id 1r5kss-001zV9-0U; Wed, 22 Nov 2023 13:55:06 +0300 Date: Wed, 22 Nov 2023 13:50:34 +0300 To: Maksim Kokryashkin Message-ID: References: <20231121231647.92696-1-max.kokryashkin@gmail.com> <20231121231647.92696-3-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231121231647.92696-3-max.kokryashkin@gmail.com> X-Mailru-Src: smtp X-4EC0790: 10 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92D71B79D2A671AE628886E7395E1296DC5DACA20BBF2B5A3182A05F538085040251EF528842E308E10DF86125765796B492EC361D678EAB80B847269F4F05316 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3DED2DACB82E709C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7AE0F15972A9DD0A8EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38B73AB1701401CD87133F6C903C01CA53D449454C0DC64B15BCC7F00164DA146DAFE8445B8C89999728AA50765F79006372A3B24BF85B2E607389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8B861051D4BA689FCF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947CE753FA5741D1AD02040F9FF01DFDA4A84AD6D5ED66289B523666184CF4C3C14F6136E347CC761E07725E5C173C3A84C304A335BCDFF8BE43BA3038C0950A5D36B5C8C57E37DE458B330BD67F2E7D9AF16D1867E19FE14079C09775C1D3CA48CF27ED053E960B195E1DD303D21008E298D5E8D9A59859A8B6B372FE9A2E580EFC725E5C173C3A84C35E849BEFB94E8FD135872C767BF85DA2F004C90652538430E4A6367B16DE6309 X-C1DE0DAB: 0D63561A33F958A5CF3E8702A20C408AADFEBEF916DA6996F2450E2079F45EA6F87CCE6106E1FC07E67D4AC08A07B9B0B355ED1E20F5346ACB5012B2E24CD356 X-C8649E89: 1C3962B70DF3F0ADE00A9FD3E00BEEDF3FED46C3ACD6F73ED3581295AF09D3DF87807E0823442EA2ED31085941D9CD0AF7F820E7B07EA4CFE64B26C6893D43818345B426C87992671B82AAC6A889FBB3A35F38D6C0964B376238D603D2F19CCF88AD3775A6B0C834D9867FC56F1A8AAD0AE0FC6572EB8A35A74DFFEFA5DC0E7F02C26D483E81D6BE5EF9655DD6DEA7D65774BB76CC95456EEC5B5AD62611EEC62B5AFB4261A09AF0 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojGZhPsaRkbbmL8phlpfuspw== X-Mailru-Sender: 11C2EC085EDE56FAC07928AF2646A76907B135243DEE02DC10DF86125765796BB67A942A63B4089ADEDBA653FF35249392D99EB8CC7091A70E183A470755BFD208F19895AA18418972D6B4FCE48DF648AE208404248635DF X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH luajit v2 2/3] Cleanup stack overflow handling. 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" Hi, Maxim! Thanks for the fixes! Please, consider my comments below. On 22.11.23, Maksim Kokryashkin wrote: > From: Mike Pall > > Reported by Peter Cawley. > > (cherry-picked from commit d2f6c55b05c716e5dbb479b7e684abaee7cf6e12) > > --- > src/lj_state.c | 15 +++++-- > .../lj-962-premature-stack-overflow.test.c | 41 +++++++++++++++++++ > 2 files changed, 52 insertions(+), 4 deletions(-) > create mode 100644 test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c > > diff --git a/src/lj_state.c b/src/lj_state.c > index 76153bad..d8a5134c 100644 > --- a/src/lj_state.c > +++ b/src/lj_state.c > @@ -121,8 +121,17 @@ void lj_state_shrinkstack(lua_State *L, MSize used) > void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) > { > MSize n; > - if (L->stacksize > LJ_STACK_MAXEX) /* Overflow while handling overflow? */ > - lj_err_throw(L, LUA_ERRERR); > + if (L->stacksize >= LJ_STACK_MAXEX) { > + /* 4. Throw 'error in error handling' when we are _over_ the limit. */ > + if (L->stacksize > LJ_STACK_MAXEX) > + lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */ I suggest covering this special case in our test. > + /* 1. We are _at_ the limit after the last growth. */ > + if (!L->status) { /* 2. Throw 'stack overflow'. */ > + L->status = LUA_ERRRUN; /* Prevent ending here again for pushed msg. */ > + lj_err_msg(L, LJ_ERR_STKOV); /* May invoke an error handler. */ > + } > + /* 3. Add space (over the limit) for pushed message and error handler. */ > + } > n = L->stacksize + need; > if (n > LJ_STACK_MAX) { > n += 2*LUA_MINSTACK; > @@ -132,8 +141,6 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) > void LJ_FASTCALL lj_state_growstack1(lua_State *L) > diff --git a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c > new file mode 100644 > index 00000000..fd7557a7 > --- /dev/null > +++ b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c > @@ -0,0 +1,41 @@ > +#include "lua.h" > +#include "lauxlib.h" > + > +#include "test.h" > +#include "utils.h" > + > +#include "lj_obj.h" Minor: Please provide rationalization for "lj_obj.h" used here (a comment about calculation of stack usage is enough). > +#include "luaconf.h" > + > +static int cur_slots = -1; > + > +static int fill_stack(lua_State *L) > +{ > + cur_slots = L->base - tvref(L->stack); > + > + while(lua_gettop(L) < LUAI_MAXSTACK) { > + cur_slots += 1; > + lua_pushinteger(L, 42); > + } > + > + return 0; > +} > + > +static int premature_stackoverflow(void *test_state) > +{ > + lua_State *L = test_state; > + lua_cpcall(L, fill_stack, NULL); > + assert_true(cur_slots == LUAI_MAXSTACK - 1); > + return TEST_EXIT_SUCCESS; > +} > + > +int main(void) > +{ > + lua_State *L = utils_lua_init(); > + const struct test_unit tgroup[] = { > + test_unit_def(premature_stackoverflow), > + }; > + const int test_result = test_run_group(tgroup, L); > + utils_lua_close(L); > + return test_result; > +} > -- > 2.39.3 (Apple Git-145) > -- Best regards, Sergey Kaplun