Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C2S crash fix #1597

Merged
merged 3 commits into from
Dec 15, 2017
Merged

C2S crash fix #1597

merged 3 commits into from
Dec 15, 2017

Conversation

avlindfors
Copy link
Contributor

This PR addresses crash of ejabberd_c2s process when receiving iq with blocking or privacy namespace

Proposed changes include:
Check if IQ is of record iq, if not return old state

The server crashes when variable IQ was not of iq record. Add check to prevent crash and return old state.
Copy link
Member

@fenek fenek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a regression test for this.

end,
Acc3 = ejabberd_router:route(To, From, Acc2, jlib:iq_to_xml(IQRes)),
{Acc3, NewStateData}.
case is_record(IQ, iq) of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more common to write:

case IQ of
    #iq{type = Type, sub_el = SubEl} = IQ ->
        {Acc2...

What is more, this case can even begin before line 2352.

Modify head of case construct in process_privacy_iq/3
Add regression tests for blocking and privacy namespaces
end,
Acc3 = ejabberd_router:route(To, From, Acc2, jlib:iq_to_xml(IQRes)),
{Acc3, NewStateData}.
case mongoose_acc:get(iq_query_info, Acc) of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use a separate function instead of case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, it's a tradeoff between large case and adding yet another function to ejabberd_c2s (and coming up with a meaningful name).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way works for me, the problem I have would be to come up with a meaningful function name.

@@ -68,7 +68,8 @@ effect_test_cases() ->
messages_from_unblocked_user_arrive_again,
messages_from_any_blocked_resource_dont_arrive,
blocking_doesnt_interfere,
blocking_propagates_to_resources
blocking_propagates_to_resources,
send_iq_with_blocking_ns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name doesn't tell precisely what the test does. Please consider iq_reply_doesnt_crash_user_process or similar.

@@ -71,7 +72,8 @@ blocking_test_cases() ->
block_jid_message_but_not_presence,
newly_blocked_presense_jid_by_new_list,
newly_blocked_presense_jid_by_list_change,
newly_blocked_presence_not_notify_self
newly_blocked_presence_not_notify_self,
send_iq_with_privacy_ns
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment in mod_blocking_SUITE.

@@ -22,6 +22,7 @@
-include_lib("common_test/include/ct.hrl").

-define(SLEEP_TIME, 50).
-define(NS_PRIVACY, <<"jabber:iq:privacy">>).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defined already in escalus/include/escalus_xmlns.hrl. You could actually include this header in mod_blocking_SUITE and remove similar define there.

escalus:story(Config, [{alice, 1}, {bob, 1}], fun(Alice, Bob) ->
QueryWithPrivacyNS = escalus_stanza:query_el(?NS_BLOCKING, []),
BobJid = escalus_utils:get_short_jid(Bob),
IQError = escalus_stanza:iq(BobJid,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 295-306 may be extracted into parametrised helper in order to reduce code duplication. The same applies to privacy_SUITE.

Remove previously defined definitions, include headerfiles
Add generic helper function in privacy_helper module for new test cases
@avlindfors
Copy link
Contributor Author

I am unsure about the placement of the new helper function in privacy_helper.erl

@fenek
Copy link
Member

fenek commented Dec 15, 2017

Merging because only one test failed - resend on unacked, our known random. Thanks!

@fenek fenek merged commit ca39886 into master Dec 15, 2017
@fenek fenek deleted the c2s-process-crash branch December 15, 2017 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants