Erlang function integer_to_binary/1 is throwing badargs exception

Hi,

The pubsub module is not able to convert node id(Nidx) from integer to binary using erlang function integer_to_binary/1.
Below id the error trace.
Any help would be great.

Internal error while processing SQL query:

 {error,badarg,[
  {erlang,integer_to_binary,[<<"451">>],[]},
  {ejabberd_sql,'-generic_escape/0-fun-1-',1,[{file,"src/ejabberd_sql.erl"},{line,632}]},
  {node_flat_sql,'-get_affiliation/2-fun-2-',3,[{file,"src/node_flat_sql.erl"},{line,343}]},
  {ejabberd_sql,generic_sql_query_format,1,[{file,"src/ejabberd_sql.erl"},{line,627}]},
  {ejabberd_sql,generic_sql_query,1,[{file,"src/ejabberd_sql.erl"},{line,623}]},
  {ejabberd_sql,sql_query_internal,1,[{file,"src/ejabberd_sql.erl"},{line,547}]},
  {ejabberd_sql,sql_query_t,1,[{file,"src/ejabberd_sql.erl"},{line,183}]},
  {node_flat_sql,get_affiliation,2,[{file,"src/node_flat_sql.erl"},{line,342}]}]}

Thank you,
Prasad

To further add to this, the

To further add to this, the Nidx is already in binary form, so the below line in node_flat_sql.erl in function get_items/3 is causing the issue:

SNidx = integer_to_binary(Nidx)

Commit for reference:
https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e2...

Commenting above line has fixed the issue.

Extra Information:
I have upgraded from 16.03 to 16.09.37(non stable release), also running Erlang/OTP 19. Please let me know if this scenario could have caused this issue.

Thank you,
Prasad

Since 16.06, the commit

Since 16.06, the commit https://github.com/processone/ejabberd/commit/d201f013b2e02ee33099df90e2...

added this line to node_flat_sql:get_items as you noticed:
SNidx = integer_to_binary(Nidx),

That Nidx is get from #pubsub_node.id in mod_pubsub.erl:

get_items(Host, Node) ->
    Action = fun (#pubsub_node{type = Type, id = Nidx}) ->
            node_call(Host, Type, get_items, [Nidx, service_jid(Host), none])

and include/pubsub.hrl says that it can be integer or binary:

-type(nodeIdx() :: pos_integer() | binary()).
%% @type nodeIdx() = integer() | binary().
%% note: pos_integer() should always be used, but we allow anything else coded
%% as binary, so one can have a custom implementation of nodetree with custom
%% indexing (see nodetree_virtual). this also allows to use any kind of key for
%% indexing nodes, as this can be usefull with external backends such as sql.

So, when the value is already a binary, that line crashes, as you reported.

I guess the line requires an improvement to handle that the value can already be a binary. There's already a function that checks this, so I committed this fix:
https://github.com/processone/ejabberd/commit/2ab72bcd009536a6bef2be04c7...

If you can try it, please confirm it works or not.

Hi, Thank you for promply

Hi,

Thank you for promply addressing the issue.

Similar changes need to be made to ejabberd_sql.erl file for this to work.
Have raised pull request for the same if that is of any help: https://github.com/processone/ejabberd/pull/1349

The changes have been verified successfully, locally.

Thank you,
Prasad

Syndicate content