From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id A1BB6266E0 for ; Sat, 23 Feb 2019 08:34:45 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IwlTXHc0f0Zx for ; Sat, 23 Feb 2019 08:34:45 -0500 (EST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 51DC9265C2 for ; Sat, 23 Feb 2019 08:34:45 -0500 (EST) Received: by mail-lj1-f193.google.com with SMTP id l5so3878428lje.1 for ; Sat, 23 Feb 2019 05:34:45 -0800 (PST) Date: Sat, 23 Feb 2019 16:34:42 +0300 From: Cyrill Gorcunov Subject: [tarantool-patches] [PATCH v2] lua/fiber: Fix abort on malformed join input Message-ID: <20190223133442.GC7198@uranus> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: =?utf-8?B?0JPQtdC+0YDQs9C40Lkg0JrQuNGA0LjRh9C10L3QutC+?= If I create a new fiber and the join to himself we get an abort: | tarantool> f = require('fiber') | --- | ... | | tarantool> f.join(f.self()) | tarantool: src/fiber.c:407: fiber_join: Assertion `fiber->flags & FIBER_IS_JOINABLE' failed. | Aborted (core dumped) we should better throw an error. v2: by georgy@ - add a testcase Signed-off-by: Cyrill Gorcunov --- src/lua/fiber.c | 6 +++++- test/app/fiber.result | 11 +++++++++++ test/app/fiber.test.lua | 7 +++++++ 3 files changed, 23 insertions(+), 1 deletion(-) Index: tarantool.git/src/lua/fiber.c =================================================================== --- tarantool.git.orig/src/lua/fiber.c +++ tarantool.git/src/lua/fiber.c @@ -676,10 +676,14 @@ lbox_fiber_join(struct lua_State *L) { struct fiber *fiber = lbox_checkfiber(L, 1); struct lua_State *child_L = fiber->storage.lua.stack; - fiber_join(fiber); struct error *e = NULL; int num_ret = 0; int coro_ref = 0; + + if (!(fiber->flags & FIBER_IS_JOINABLE)) + luaL_error(L, "the fiber is not joinable"); + fiber_join(fiber); + if (child_L != NULL) { coro_ref = lua_tointeger(child_L, -1); lua_pop(child_L, 1); Index: tarantool.git/test/app/fiber.result =================================================================== --- tarantool.git.orig/test/app/fiber.result +++ tarantool.git/test/app/fiber.result @@ -1454,6 +1454,17 @@ ch1:put(1) while f:status() ~= 'dead' do fiber.sleep(0.01) end --- ... +-- +-- Test if fiber join() does not crash +-- if unjoinable +-- +fj = require('fiber') +--- +... +fj.join(fj.self()) +--- +- error: the fiber is not joinable +... -- cleanup test_run:cmd("clear filter") --- Index: tarantool.git/test/app/fiber.test.lua =================================================================== --- tarantool.git.orig/test/app/fiber.test.lua +++ tarantool.git/test/app/fiber.test.lua @@ -623,6 +623,13 @@ ch1:put(1) while f:status() ~= 'dead' do fiber.sleep(0.01) end +-- +-- Test if fiber join() does not crash +-- if unjoinable +-- +fj = require('fiber') +fj.join(fj.self()) + -- cleanup test_run:cmd("clear filter")