Skip to content

Commit

Permalink
mod_private: Don't crash on invalid bookmarks
Browse files Browse the repository at this point in the history
Catch failures while decoding the conference bookmark element.
  • Loading branch information
weiss committed Jan 28, 2025
1 parent a19ab9f commit eca3204
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/mod_private.erl
Original file line number Diff line number Diff line change
Expand Up @@ -447,17 +447,20 @@ pubsub_delete_item(_, _, _, _, _) ->

-spec pubsub_item_to_storage_bookmark(#pubsub_item{}) -> {true, bookmark_conference()} | false.
pubsub_item_to_storage_bookmark(#pubsub_item{itemid = {Id, _}, payload = [#xmlel{} = B | _]}) ->
case xmpp:decode(B) of
try
#pep_bookmarks_conference{name = Name, autojoin = AutoJoin, nick = Nick,
password = Password} ->
try jid:decode(Id) of
#jid{} = Jid ->
{true, #bookmark_conference{jid = Jid, name = Name, autojoin = AutoJoin, nick = Nick,
password = Password}}
catch _:_ ->
false
end;
_ ->
password = Password} = xmpp:decode(B),
#jid{} = Jid = jid:decode(Id),
{true, #bookmark_conference{jid = Jid, name = Name,
autojoin = AutoJoin, nick = Nick,
password = Password}}
catch
_:{xmpp_codec, Why} ->
?DEBUG("Failed to decode bookmark element (~ts): ~ts",
[Id, xmpp:format_error(Why)]),
false;
_:{bad_jid, _} ->
?DEBUG("Failed to decode bookmark ID (~ts)", [Id]),
false
end;
pubsub_item_to_storage_bookmark(_) ->
Expand Down

0 comments on commit eca3204

Please sign in to comment.