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 CBB3B6FC8E; Mon, 26 Apr 2021 13:11:06 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org CBB3B6FC8E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1619431866; bh=Ak5G7mF6HnTJv6Leky8SlFOR4O0gVGhP11B87BV9CAc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=KHDzo3wCPOWLaR70QCLbU4YpG0tWabfpEfC7TlyqMjQEy3EkPvxERkM4C1MbXCLPd GZlWHn5jiRZpvP5v+KhsEadptnGy2UDNaY2tf7T0EXpZIfNrdq1RETTKJsm07I+qaj i5BFhJ9ZfJMxXgQnza0r3k4QSLANx2ZIdlSVugCE= Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (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 E5C4170310 for ; Mon, 26 Apr 2021 13:10:28 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org E5C4170310 Received: by mail-lf1-f53.google.com with SMTP id w9so3564689lfr.12 for ; Mon, 26 Apr 2021 03:10:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BDVMyi98jQbDNTuHrTn98ibL2Tg3+qlonW0+V9BZfhk=; b=tIx+9/aio5gi5ue59Sf2yXq73D+Tr2U2FCyB3vthUyJLqHdtokm+zbUAEBeOKY7GQw f89MpN3XW4dKlR22e5WP+afI9k0IuY0ysKHPy2oSxmFXlTk7bf7R7yviGEGuTQQ8IoES OihDuIeLCH6S2yM0r5L1acbC3M+hajf2aS2yN9K8I5NmGmdi4uwqA11jqedEZ7f2n1DO eygkJWObgnkI2qm/C/G2WwnAu6UeGpH7HnHV5NBRt8FUGeR1P0bB8sMmnsnynOVpf66o pfHbGSWGBMBmuXuJ6pDYE10yXfRLOTfYMYffdF9G2uf849TA6TrjmH4jpYodRLAR8efW B/Fg== X-Gm-Message-State: AOAM530bGNvXlDdOJ+h7tdFf/xLXRsXW6jluKy4VDfDad34V2Tlaj71V +Ea93J+7wcubiWAzZe9QBk5XtiktS0w= X-Google-Smtp-Source: ABdhPJzKQxahuYSqMQew0x/aaVqmka/b/bkJlVzSejx9SWAxJFBrVCDtjXuw6aVkMOQVpQLq4HEuYQ== X-Received: by 2002:a19:e309:: with SMTP id a9mr12083399lfh.222.1619431827889; Mon, 26 Apr 2021 03:10:27 -0700 (PDT) Received: from grain.localdomain ([5.18.199.94]) by smtp.gmail.com with ESMTPSA id y14sm1392390ljk.140.2021.04.26.03.10.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 03:10:27 -0700 (PDT) Received: by grain.localdomain (Postfix, from userid 1000) id 9D72E5601F7; Mon, 26 Apr 2021 13:10:01 +0300 (MSK) To: tml Date: Mon, 26 Apr 2021 13:10:00 +0300 Message-Id: <20210426101000.278874-3-gorcunov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210426101000.278874-1-gorcunov@gmail.com> References: <20210426101000.278874-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/2] fiber: fiber_join -- don't crash on misuse 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: Cyrill Gorcunov via Tarantool-patches Reply-To: Cyrill Gorcunov Cc: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" In case if we call jiber_join() over the nonjoinable fiber we trigger an assert and crash execution (on debug build). On release build the asserts will be zapped and won't cause problems but there is an another one -- the target fiber will cause double fiber_reset() calls which in result cause to unregister_fid with id = 0 (not causing crash but definitely out of intention) and we will drop stack protection which might be not ours anymore. Thus lets return error just like Lua interface does. Since nobody complained about this bug yet I think such combination is not use commonly in external C modules and we can change the API behaviour. Fixes #6046 Signed-off-by: Cyrill Gorcunov --- src/lib/core/fiber.c | 5 ++++- test/unit/fiber.cc | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c index baf78a130..dd7498dd7 100644 --- a/src/lib/core/fiber.c +++ b/src/lib/core/fiber.c @@ -615,7 +615,10 @@ fiber_join(struct fiber *fiber) int fiber_join_timeout(struct fiber *fiber, double timeout) { - assert(fiber->flags & FIBER_IS_JOINABLE); + if (!(fiber->flags & FIBER_IS_JOINABLE)) { + diag_set(IllegalParams, "the fiber is not joinable"); + return -1; + } if (! fiber_is_dead(fiber)) { bool exceeded = false; diff --git a/test/unit/fiber.cc b/test/unit/fiber.cc index 9c1a23bdd..fbdd82772 100644 --- a/test/unit/fiber.cc +++ b/test/unit/fiber.cc @@ -96,6 +96,9 @@ fiber_join_test() header(); struct fiber *fiber = fiber_new_xc("join", noop_f); + /* gh-6046: crash on attempt to join non joinable */ + fiber_set_joinable(fiber, false); + fiber_join(fiber); fiber_set_joinable(fiber, true); fiber_wakeup(fiber); fiber_join(fiber); -- 2.30.2