[Tarantool-patches] [PATCH v3 2/2] fiber: fiber_join -- don't crash on misuse
Cyrill Gorcunov
gorcunov at gmail.com
Thu Apr 29 14:10:31 MSK 2021
In case if we call fiber_join() over the non joinable 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.
Since we're not allowed to break API on C level lets just
panic early in case of such misuse, it is a way better than
continue operating with potentially screwed data in memory.
Fixes #6046
Signed-off-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
issue https://github.com/tarantool/tarantool/issues/6046
branch gorcunov/gh-6046-fiber-join-3
changelogs/unreleased/gh-6046-fiber-join-misuse.md | 6 ++++++
src/lib/core/fiber.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
create mode 100644 changelogs/unreleased/gh-6046-fiber-join-misuse.md
diff --git a/changelogs/unreleased/gh-6046-fiber-join-misuse.md b/changelogs/unreleased/gh-6046-fiber-join-misuse.md
new file mode 100644
index 000000000..32c15566d
--- /dev/null
+++ b/changelogs/unreleased/gh-6046-fiber-join-misuse.md
@@ -0,0 +1,6 @@
+## bugfix/core
+
+* Fixed lack of testing for non noinable fibers in `fiber_join()` call.
+ This could lead to unpredictable results. Note the issue affects C
+ level only, in Lua interface `fiber::join()`` the protection is
+ turned on already.
diff --git a/src/lib/core/fiber.c b/src/lib/core/fiber.c
index a4b60e864..196dffe26 100644
--- a/src/lib/core/fiber.c
+++ b/src/lib/core/fiber.c
@@ -620,7 +620,8 @@ 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) == 0)
+ panic("the fiber is not joinable");
if (! fiber_is_dead(fiber)) {
bool exceeded = false;
--
2.30.2
More information about the Tarantool-patches
mailing list