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 8C9876D4677; Wed, 22 Nov 2023 02:18:25 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8C9876D4677 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1700608705; bh=d55Q+ZLV516UDmht/LEBBk9+gbAEvfPJF0LrfgYh3dI=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=mL6w1U/zJOxiRNXRk6rGjlF4ZhLCuUQ5cGpnx3Fcpq9cXa75WEsUG4bzzK2UCap6Z H+vMIE/vytR3eW2iWSZ4/h5iKsA6DexmldPYWaWEq5YKm99PVcXsStgf1OmSF2v2ja FJtdCR+yWaFVqC23O8mNjp4nD6dYAJ97D2jMf2WY= Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 4FFE66D4670 for ; Wed, 22 Nov 2023 02:17:11 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4FFE66D4670 Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-507975d34e8so8723193e87.1 for ; Tue, 21 Nov 2023 15:17:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700608630; x=1701213430; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TXWkLJYTo+oNFCXVzzT1F/G++k0a0rSpwcA2H8PuIWQ=; b=lgP94PrXVfRHOOGuy0o2m5uEJA9ow/liHlTuJAEVCzKEiuZLVPbdnpRJ5TeOL68N/F EJgZ9yx4iShLv4jPL/Kq+QKSjm5pbLjfaVe9mJMLttXnZJP5ktbWvUh33DN2IRzJXx+E gLL4AzUuVirD87X4zZNXqm6rKXeTWuTxMzdh4Fy9PejjIbYWK4UKmZYdJ5VDlBjpnl7d pV2Y7o3T2sKC1TXGD+P0R5ZG2QT0TqQ1Q2Kcmct6C1hIcOqdUHX1qxxyvGIs/xmPWa7s 81VEoWn9HV8l/wFzB6ozhYlMk+8D80dGh5l6zhd/+OAva5C2ipk7BUgwLseHwHQ4pAgJ Q6hA== X-Gm-Message-State: AOJu0YwQrufFR+ziqL77tPtNVehJMSiZkhcIo50TYnRDl4jTvpvvQtia Q5W4unna4INHPTy1k3jiakSBY+hzDO4ciQ== X-Google-Smtp-Source: AGHT+IGeH4RHEigPOtyzgPPiDs78yueauNWByPpunylpE7e3ocTo8IDANITeN8DrCV517G2lKCBtWQ== X-Received: by 2002:a05:6512:e96:b0:4ff:9a75:211e with SMTP id bi22-20020a0565120e9600b004ff9a75211emr619283lfb.42.1700608630063; Tue, 21 Nov 2023 15:17:10 -0800 (PST) Received: from localhost.localdomain (95-24-1-238.broadband.corbina.ru. [95.24.1.238]) by smtp.gmail.com with ESMTPSA id z1-20020a056512370100b004f755ceafbcsm1636371lfr.217.2023.11.21.15.17.09 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 21 Nov 2023 15:17:09 -0800 (PST) To: tarantool-patches@dev.tarantool.org, sergeyb@tarantool.org, skaplun@tarantool.org, m.kokryashkin@tarantool.org Date: Wed, 22 Nov 2023 02:16:47 +0300 Message-Id: <20231121231647.92696-4-max.kokryashkin@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-145) In-Reply-To: <20231121231647.92696-1-max.kokryashkin@gmail.com> References: <20231121231647.92696-1-max.kokryashkin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH luajit v2 3/3] Follow-up fix for stack overflow handling cleanup. 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: Maksim Kokryashkin via Tarantool-patches Reply-To: Maksim Kokryashkin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" From: Mike Pall (cherry-picked from commit aa6b15c1a8922848bd6f596ba384824ca3fe0f5f) The stack overflow error is thrown in `lj_state_growstack` only if the coroutine status is `OK`, however, stack overflow can happen on a yielded coroutine too. This patch fixes the condition for status, so now the error thrown on yielded coroutines too. Maxim Kokryashkin: * added the description and the test for the patch Part of tarantool/tarantool#9145 --- src/lj_state.c | 2 +- .../lj-962-premature-stack-overflow.test.c | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/lj_state.c b/src/lj_state.c index d8a5134c..01d4901a 100644 --- a/src/lj_state.c +++ b/src/lj_state.c @@ -126,7 +126,7 @@ void LJ_FASTCALL lj_state_growstack(lua_State *L, MSize need) if (L->stacksize > LJ_STACK_MAXEX) lj_err_throw(L, LUA_ERRERR); /* Does not invoke an error handler. */ /* 1. We are _at_ the limit after the last growth. */ - if (!L->status) { /* 2. Throw 'stack overflow'. */ + if (L->status < LUA_ERRRUN) { /* 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. */ } 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 index fd7557a7..39a95998 100644 --- a/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c +++ b/test/tarantool-c-tests/lj-962-premature-stack-overflow.test.c @@ -21,6 +21,20 @@ static int fill_stack(lua_State *L) return 0; } +static int immediate_yield(lua_State *L) +{ + return lua_yield(L, 0); +} + +static int overflow_suspended_coro(lua_State *L) +{ + lua_State *newL = lua_newthread(L); + lua_pushcfunction(newL, immediate_yield); + lua_resume(newL, 0); + fill_stack(newL); + return 0; +} + static int premature_stackoverflow(void *test_state) { lua_State *L = test_state; @@ -29,11 +43,20 @@ static int premature_stackoverflow(void *test_state) return TEST_EXIT_SUCCESS; } +static int stackoverflow_on_suspended_coro(void *test_state) +{ + lua_State *L = test_state; + int status = lua_cpcall(L, overflow_suspended_coro, NULL); + assert_true(status == LUA_ERRRUN); + return TEST_EXIT_SUCCESS; +} + int main(void) { lua_State *L = utils_lua_init(); const struct test_unit tgroup[] = { test_unit_def(premature_stackoverflow), + test_unit_def(stackoverflow_on_suspended_coro), }; const int test_result = test_run_group(tgroup, L); utils_lua_close(L); -- 2.39.3 (Apple Git-145)