]> granicus.if.org Git - ejabberd/commitdiff
Function fix_from_to/2 should not crash when 'from' is undefined
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 17 Apr 2017 22:38:35 +0000 (01:38 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 17 Apr 2017 22:38:35 +0000 (01:38 +0300)
Fixes #1678

src/ejabberd_c2s.erl

index c1f1e2fa587b17b8127e1eaa3fdaab2a940deb35..e0a10e6592b37a7c0d50b0a7ea5703fe6057a808 100644 (file)
@@ -867,13 +867,17 @@ get_conn_type(State) ->
 -spec fix_from_to(xmpp_element(), state()) -> stanza().
 fix_from_to(Pkt, #{jid := JID}) when ?is_stanza(Pkt) ->
     #jid{luser = U, lserver = S, lresource = R} = JID,
-    From = xmpp:get_from(Pkt),
-    From1 = case jid:tolower(From) of
-               {U, S, R} -> JID;
-               {U, S, _} -> jid:replace_resource(JID, From#jid.resource);
-               _ -> From
-           end,
-    xmpp:set_from_to(Pkt, From1, JID);
+    case xmpp:get_from(Pkt) of
+       undefined ->
+           Pkt;
+       From ->
+           From1 = case jid:tolower(From) of
+                       {U, S, R} -> JID;
+                       {U, S, _} -> jid:replace_resource(JID, From#jid.resource);
+                       _ -> From
+                   end,
+           xmpp:set_from_to(Pkt, From1, JID)
+    end;
 fix_from_to(Pkt, _State) ->
     Pkt.