From e8eb6bc2b484a51c5bfff0aafe511a844c028dc4 Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Mon, 8 Jul 2019 10:45:13 +0300 Subject: [PATCH] Avoid crashing of ejabberd_iq process on invalid callback --- src/ejabberd_iq.erl | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/ejabberd_iq.erl b/src/ejabberd_iq.erl index cda5b57c9..31297fd29 100644 --- a/src/ejabberd_iq.erl +++ b/src/ejabberd_iq.erl @@ -36,6 +36,7 @@ -include("xmpp.hrl"). -include("logger.hrl"). +-include("ejabberd_stacktrace.hrl"). -record(state, {expire = infinity :: timeout()}). -type state() :: #state{}. @@ -74,7 +75,8 @@ init([]) -> {ok, #state{}}. handle_call(Request, From, State) -> - {stop, {unexpected_call, Request, From}, State}. + ?WARNING_MSG("Unexpected call from ~p: ~p", [From, Request]), + noreply(State). handle_cast({restart_timer, Expire}, State) -> State1 = State#state{expire = min(Expire, State#state.expire)}, @@ -171,7 +173,13 @@ calc_checksum(Data) -> -spec callback(atom() | pid(), #iq{} | timeout, term()) -> any(). callback(undefined, IQRes, Fun) -> - Fun(IQRes); + try Fun(IQRes) + catch ?EX_RULE(Class, Reason, St) -> + StackTrace = ?EX_STACK(St), + ?ERROR_MSG("Failed to process iq response:~n~s~n** ~s", + [xmpp:pp(IQRes), + misc:format_exception(2, Class, Reason, StackTrace)]) + end; callback(Proc, IQRes, Ctx) -> try Proc ! {iq_reply, IQRes, Ctx}