ejabberd - Comments for "Pubsub bugs" https://www.ejabberd.im/node/4849 en Hi, everyone, I posted this https://www.ejabberd.im/node/4849#comment-57670 <p>Hi, everyone, I posted this message serveral days ago, but nobody answers me, so I modified the source code myself, and ejabberd can work now, here are my modifications:</p> <div class="codeblock"><code>diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl<br />index fc50a1c..c2432c6 100644<br />--- a/src/mod_pubsub/mod_pubsub.erl<br />+++ b/src/mod_pubsub/mod_pubsub.erl<br />@@ -2639,9 +2639,9 @@ purge_node(Host, Node, Owner) -&gt;<br /> get_items(Host, Node, From, SubId, SMaxItems, ItemIds) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; MaxItems =<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if<br />-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SMaxItems == &quot;&quot; -&gt; get_max_items_node(Host);<br />+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SMaxItems == &lt;&lt;&quot;&quot;&gt;&gt; -&gt; get_max_items_node(Host);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true -&gt;<br />-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case catch list_to_integer(SMaxItems) of<br />+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case catch list_to_integer(binary_to_list(SMaxItems)) of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&#039;EXIT&#039;, _} -&gt; {error, &#039;bad-request&#039;};<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Val -&gt; Val<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end<br />@@ -2957,12 +2957,13 @@ get_options(Host, Node, JID, SubId, Lang) -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; end. <p> get_options_helper(JID, Lang, Node, Nidx, SubId, Type) -&gt;<br />-&nbsp;&nbsp;&nbsp; Subscriber = try exmpp_jid:parse(JID) of<br />+&nbsp;&nbsp;&nbsp; {U, S, R} = try exmpp_jid:parse(JID) of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; J -&gt; jlib:short_jid(J)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ -&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exmpp_jid:make(&quot;&quot;, &quot;&quot;, &quot;&quot;) %% TODO, check if use &lt;&lt;&gt;&gt; instead of &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end,<br />+&nbsp;&nbsp;&nbsp; Subscriber = #jid{node = U, domain = S, resource = R},<br />&nbsp;&nbsp;&nbsp;&nbsp; {result, Subs} = node_call(Type, get_subscriptions,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [Nidx, Subscriber]),<br />&nbsp;&nbsp;&nbsp;&nbsp; SubIds = lists:foldl(fun({subscribed, SID}, Acc) -&gt;</p></code></div> <p>After that, I tried some other features in pubsub module, and now, I find another bug, here it is:<br /> User m9@localhost is trying to subscribe to a node owned by test@localhost, and m9 is in test's roster group "stranger". The acces model of the node is "roster", and the allowed roster groups contain group "stranger", but the server finally gives the error "not-in-roster-group". </p> <p>After tracking this problem, I find the bug is in function get_roster_info/4:</p> <div class="codeblock"><code>mod_pubsub.erl: <p>get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) -&gt;<br />&nbsp;&nbsp;&nbsp; {Subscription, Groups} =<br /> ejabberd_hooks:run_fold(<br /> &nbsp; roster_get_jid_info, OwnerServer,<br /> &nbsp; {none, []},<br /> &nbsp; [OwnerUser, OwnerServer, exmpp_jid:make({SubscriberUser, SubscriberServer, undefined})]),<br />&nbsp;&nbsp;&nbsp; PresenceSubscription = (Subscription == both) orelse (Subscription == from)<br /> orelse ({OwnerUser, OwnerServer} == {SubscriberUser, SubscriberServer}),<br />&nbsp;&nbsp;&nbsp; RosterGroup = lists:any(fun(Group) -&gt;<br /> &nbsp;&nbsp;&nbsp; lists:member(Group, AllowedGroups)<br /> &nbsp;&nbsp;&nbsp; end, Groups),<br />&nbsp;&nbsp;&nbsp; {PresenceSubscription, RosterGroup};</p></code></div> <p>When calling lists:member(Group, AllowedGroups), the context is like this:<br /> <cite><br /> &lt; AllowedGroups = ["stranger","friend","family"]<br /> &lt; Owners = [{&lt;&lt;"test"&gt;&gt;,&lt;&lt;"localhost"&gt;&gt;,undefined}]<br /> &lt; Groups = [&lt;&lt;"stranger"&gt;&gt;]<br /> &lt; AllowedGroups = ["stranger","friend","family"]<br /> </cite><br /> We can see the type of Group doesn't match the type of elements in list AllowedGroups, so the return value will always be false. The bug is obvious, and my concern is from when and from where, those bugs are brought in, and there may be other bugs similar to this, I really hope someone could give me a reply. please, any comments or suggestions are greatly appreciated.</p> Sun, 31 Jul 2011 14:06:58 +0000 dinosaurkfb comment 57670 at https://www.ejabberd.im