From 85e7a543c9c5729752ad0cc83a51806f77a3fb65 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Fri, 22 Apr 2022 09:54:34 -0300 Subject: Prevent eating "Close Context" --- src/lib.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index 3343fed..ac8ef85 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -838,6 +838,13 @@ impl<'ph> PluginHandle<'ph> { let f: Rc = rc_clone_from_raw(ud as *const HookUd); (f)(word, ptr::null(), ptr::null()).do_eat as c_int } + // we use "Close Context" to clean up dangling pointers. + // hexchat lets plugins/hooks eat "Close Context" from eachother (tho + // not from hexchat, for good reason), so this can still be unsound + // if other plugins eat "Close Context". in those cases, we'd consider + // those plugins to be faulty, tho it'd be nice if hexchat handled it. + // we still do our best to be well-behaved. + let suppress_eat = name.eq_ignore_ascii_case("Close Context"); let b: Rc = { let ph = self.data; let info = self.info; @@ -849,7 +856,10 @@ impl<'ph> PluginHandle<'ph> { call_hook_protected(ph.ph, move || { let mut ph = PluginHandle::new(ph, info, contexts); let word = Word::new(word); - cb(&mut ph, word) + match cb(&mut ph, word) { + _ if suppress_eat => EAT_NONE, + eat => eat, + } }) } })) -- cgit 1.4.1