From 6bfacf0e1e1f07570e43a60ecf9f94fb5ea04638 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Date: Tue, 19 Dec 2023 13:02:46 +0100 Subject: [PATCH] Check the thread is ready before adding events Prevents segmentation faults when accessing the NULL stream buffer without a clear message of what is happening. --- CHANGELOG.md | 2 ++ src/rt/ovni.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b377a33..20549b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Calling `ovni_thread_isready()` after `ovni_thread_free()` now returns 0. +- Emitting events in a non-ready thread now aborts the program with a + message rather than causing a segfault. ## [1.5.0] - 2023-12-15 diff --git a/src/rt/ovni.c b/src/rt/ovni.c index 3c7bcdf..537a8fb 100644 --- a/src/rt/ovni.c +++ b/src/rt/ovni.c @@ -767,6 +767,9 @@ add_flush_events(uint64_t t0, uint64_t t1) static void ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize) { + if (!rthread.ready) + die("thread is not initialized"); + int flushed = 0; uint64_t t0, t1; @@ -808,6 +811,9 @@ ovni_ev_add_jumbo(struct ovni_ev *ev, const uint8_t *buf, uint32_t bufsize) static void ovni_ev_add(struct ovni_ev *ev) { + if (!rthread.ready) + die("thread is not initialized"); + int flushed = 0; uint64_t t0, t1;