]> granicus.if.org Git - ejabberd/commitdiff
Ignore malformed parameters for mod_irc module
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 7 Jun 2014 03:45:19 +0000 (07:45 +0400)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Sat, 7 Jun 2014 03:45:36 +0000 (07:45 +0400)
src/mod_irc.erl

index 5001df076227a3b0406d5fb7eec811e21062401a..88f53a1c687e784d4a20193698f66c30ba556c0e 100644 (file)
@@ -601,7 +601,7 @@ get_data(LServer, Host, From, odbc) ->
                                        <<"';">>])
        of
       {selected, [<<"data">>], [[SData]]} ->
-         data_to_binary(ejabberd_odbc:decode_term(SData));
+         data_to_binary(From, ejabberd_odbc:decode_term(SData));
       {'EXIT', _} -> error;
       {selected, _, _} -> empty
     end.
@@ -712,7 +712,7 @@ get_form(_ServerHost, _Host, _, _, _Lang) ->
 
 set_data(ServerHost, Host, From, Data) ->
     LServer = jlib:nameprep(ServerHost),
-    set_data(LServer, Host, From, data_to_binary(Data),
+    set_data(LServer, Host, From, data_to_binary(From, Data),
             gen_mod:db_type(LServer, ?MODULE)).
 
 set_data(_LServer, Host, From, Data, mnesia) ->
@@ -1218,27 +1218,36 @@ get_username_and_connection_params(Data) ->
                  end,
     {Username, ConnParams}.
 
-data_to_binary(Data) ->
+data_to_binary(JID, Data) ->
     lists:map(
       fun({username, U}) ->
               {username, iolist_to_binary(U)};
          ({connections_params, Params}) ->
-              {connections_params,
-               lists:map(
-                 fun({S}) ->
-                         {iolist_to_binary(S)};
-                    ({S, E}) ->
-                         {iolist_to_binary(S), iolist_to_binary(E)};
-                    ({S, E, Port}) ->
-                         {iolist_to_binary(S), iolist_to_binary(E), Port};
-                    ({S, E, Port, P}) ->
-                         {iolist_to_binary(S), iolist_to_binary(E),
-                          Port, iolist_to_binary(P)}
-                 end, Params)};
+             {connections_params,
+              lists:flatmap(
+                fun(Param) ->
+                        try
+                            [conn_param_to_binary(Param)]
+                        catch _:_ ->
+                                ?ERROR_MSG("failed to convert parameter "
+                                           " ~p for user ~s",
+                                           [Param, jlib:jid_to_string(JID)]),
+                                []
+                        end
+                end, Params)};
          (Opt) ->
               Opt
       end, Data).
 
+conn_param_to_binary({S}) ->
+    {iolist_to_binary(S)};
+conn_param_to_binary({S, E}) ->
+    {iolist_to_binary(S), iolist_to_binary(E)};
+conn_param_to_binary({S, E, Port}) when is_integer(Port) ->
+    {iolist_to_binary(S), iolist_to_binary(E), Port};
+conn_param_to_binary({S, E, Port, P}) when is_integer(Port) ->
+    {iolist_to_binary(S), iolist_to_binary(E), Port, iolist_to_binary(P)}.
+
 conn_params_to_list(Params) ->
     lists:map(
       fun({S}) ->
@@ -1261,10 +1270,11 @@ update_table() ->
             fun(#irc_custom{us_host = {_, H}}) -> H end,
             fun(#irc_custom{us_host = {{U, S}, H},
                             data = Data} = R) ->
+                   JID = jlib:make_jid(U, S, <<"">>),
                     R#irc_custom{us_host = {{iolist_to_binary(U),
                                              iolist_to_binary(S)},
                                             iolist_to_binary(H)},
-                                 data = data_to_binary(Data)}
+                                 data = data_to_binary(JID, Data)}
             end);
       _ ->
          ?INFO_MSG("Recreating irc_custom table", []),