]> granicus.if.org Git - ejabberd/commitdiff
XEP-0198: Cope with invalid 'from'/'to' attributes
authorHolger Weiss <holger@zedat.fu-berlin.de>
Thu, 6 Oct 2016 21:20:45 +0000 (23:20 +0200)
committerHolger Weiss <holger@zedat.fu-berlin.de>
Thu, 6 Oct 2016 21:20:45 +0000 (23:20 +0200)
Check whether the 'from' and 'to' attributes are valid before bouncing
or resending a stanza from the stream management queue.  They might be
invalid in certain corner cases.

Thanks to Evgeniy for spotting this.

src/ejabberd_c2s.erl

index 226c5e0da4cf351af97076fb705cc1542eeaeca3..6068c85ef73e166094e4ae52d4d7dbf8bfdb8202 100644 (file)
@@ -2998,10 +2998,13 @@ handle_unacked_stanzas(#state{mgmt_state = MgmtState} = StateData, F)
          lists:foreach(
            fun({_, Time, #xmlel{attrs = Attrs} = El}) ->
                    From_s = fxml:get_attr_s(<<"from">>, Attrs),
-                   From = jid:from_string(From_s),
                    To_s = fxml:get_attr_s(<<"to">>, Attrs),
-                   To = jid:from_string(To_s),
-                   F(From, To, El, Time)
+                   case {jid:from_string(From_s), jid:from_string(To_s)} of
+                     {#jid{} = From, #jid{} = To} ->
+                         F(From, To, El, Time);
+                     {_, _} ->
+                         ?DEBUG("Dropping stanza due to invalid JID(s)", [])
+                   end
            end, queue:to_list(Queue))
     end;
 handle_unacked_stanzas(_StateData, _F) ->