From 089eaa52e06c5e12ed1cc965ec4088f37f78aaaa Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 27 Jun 2016 20:55:07 +0100 Subject: [PATCH] Detect recursive hook run and abort in that case Fixes #709 --- src/hook_manager.cc | 10 ++++++++++ src/hook_manager.hh | 1 + 2 files changed, 11 insertions(+) diff --git a/src/hook_manager.cc b/src/hook_manager.cc index 2a29d5cc..bd83b976 100644 --- a/src/hook_manager.cc +++ b/src/hook_manager.cc @@ -51,6 +51,16 @@ void HookManager::run_hook(StringView hook_name, if (hook_list_it == m_hook.end()) return; + if (contains(m_running_hooks, std::make_pair(hook_name, param))) + { + auto error = format("recursive call of hook {}/{}, aborting", hook_name, param); + write_to_debug_buffer(error); + throw runtime_error(std::move(error)); + } + + m_running_hooks.emplace_back(hook_name, param); + auto pop_running_hook = on_scope_end([this]{ m_running_hooks.pop_back(); }); + using Clock = std::chrono::steady_clock; using TimePoint = Clock::time_point; diff --git a/src/hook_manager.hh b/src/hook_manager.hh index f1680d36..d6b8d0a8 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -30,6 +30,7 @@ private: SafePtr m_parent; IdMap, MemoryDomain::Hooks> m_hook; + mutable Vector> m_running_hooks; }; }