From f21ef43b0c74e59710ec5fa4d612d4174bf3592d Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 6 Sep 2022 16:32:47 +0200 Subject: [PATCH] vici: Ignore NULL message in raise_event() There are a lot of calls like this: this->dispatcher->raise_event(this->dispatcher, "...", 0, b->finalize(b)); However, if finalize() fails, e.g. because a previous call to add() failed due to the size limit, it returns NULL. This then caused a segmentation fault in raise_event() when it interacted with that value. Closes strongswan/strongswan#1278 --- src/libcharon/plugins/vici/suites/test_event.c | 3 +++ src/libcharon/plugins/vici/vici_dispatcher.c | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/libcharon/plugins/vici/suites/test_event.c b/src/libcharon/plugins/vici/suites/test_event.c index 0c1121cba..6b4ac9def 100644 --- a/src/libcharon/plugins/vici/suites/test_event.c +++ b/src/libcharon/plugins/vici/suites/test_event.c @@ -60,6 +60,9 @@ START_TEST(test_event) ck_assert(vici_register(conn, "test", event_cb, &count) == 0); ck_assert(vici_register(conn, "nonexistent", event_cb, &count) != 0); + /* should just get ignored */ + dispatcher->raise_event(dispatcher, "test", 0, NULL); + dispatcher->raise_event(dispatcher, "test", 0, vici_message_create_from_args( VICI_KEY_VALUE, "key1", chunk_from_str("value1"), VICI_END)); diff --git a/src/libcharon/plugins/vici/vici_dispatcher.c b/src/libcharon/plugins/vici/vici_dispatcher.c index bc85d41d5..818cd0e7c 100644 --- a/src/libcharon/plugins/vici/vici_dispatcher.c +++ b/src/libcharon/plugins/vici/vici_dispatcher.c @@ -497,6 +497,11 @@ METHOD(vici_dispatcher_t, raise_event, void, event_t *event; u_int *current; + if (!message) + { + return; + } + this->mutex->lock(this->mutex); event = this->events->get(this->events, name); if (event)