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

ejabberd_http crash when listening on unix socket #3894

Closed
sloonz opened this issue Sep 4, 2022 · 3 comments
Closed

ejabberd_http crash when listening on unix socket #3894

sloonz opened this issue Sep 4, 2022 · 3 comments

Comments

@sloonz
Copy link

sloonz commented Sep 4, 2022

Environment

  • ejabberd version: 22.05
  • Erlang version: Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 13.0.3
  • OS: Linux (Arch)
  • Installed from: distro package

Configuration (only if needed): grep -Ev '^$|^\s*#' ejabberd.yml

listen:
  - port: "unix:/home/ejabberd/run/ejabberd.sock"
    module: ejabberd_http
    request_handlers:
      /admin: ejabberd_web_admin
      /bosh: mod_bosh
      /ws: ejabberd_http_ws
      /chat: mod_conversejs
    custom_headers:
      "Access-Control-Allow-Origin": "*"
      "Access-Control-Allow-Methods": "*"
      "Access-Control-Allow-Headers": "*"

Errors from error.log/crash.log

2022-09-04 10:55:02.550602+00:00 [error] <0.495.0>@proc_lib:crash_report/4:539 CRASH REPORT:
  crasher:
    initial call: ejabberd_http:init/3
    pid: <0.495.0>
    registered_name: []
    exception error: bad argument
      in function  list_to_binary/1
         called as list_to_binary({error,einval})
         *** argument 1: not an iolist term
      in call from misc:ip_to_list/1 (src/misc.erl, line 231)
      in call from ejabberd_http:analyze_ip_xff/2 (src/ejabberd_http.erl, line 532)
      in call from ejabberd_http:process_request/1 (src/ejabberd_http.erl, line 477)
      in call from ejabberd_http:process_header/2 (src/ejabberd_http.erl, line 293)
      in call from ejabberd_http:parse_headers/1 (src/ejabberd_http.erl, line 218)
      in call from ejabberd_http:init/3 (src/ejabberd_http.erl, line 142)
    ancestors: [ejabberd_http_sup,ejabberd_sup,<0.121.0>]
    message_queue_len: 0
    messages: []
    links: [<0.482.0>,#Port<0.21>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 987
    stack_size: 28
    reductions: 1899
  neighbours:

2022-09-04 10:55:02.569294+00:00 [error] <0.482.0>@supervisor:do_restart/3:751 SUPERVISOR REPORT:
    supervisor: {local,ejabberd_http_sup}
    errorContext: child_terminated
    reason: {badarg,[{erlang,list_to_binary,
                             [{error,einval}],
                             [{error_info,#{module => erl_erts_errors}}]},
                     {misc,ip_to_list,1,[{file,"src/misc.erl"},{line,231}]},
                     {ejabberd_http,analyze_ip_xff,2,
                                    [{file,"src/ejabberd_http.erl"},
                                     {line,532}]},
                     {ejabberd_http,process_request,1,
                                    [{file,"src/ejabberd_http.erl"},
                                     {line,477}]},
                     {ejabberd_http,process_header,2,
                                    [{file,"src/ejabberd_http.erl"},
                                     {line,293}]},
                     {ejabberd_http,parse_headers,1,
                                    [{file,"src/ejabberd_http.erl"},
                                     {line,218}]},
                     {ejabberd_http,init,3,
                                    [{file,"src/ejabberd_http.erl"},
                                     {line,142}]},
                     {proc_lib,init_p_do_apply,3,
                               [{file,"proc_lib.erl"},{line,240}]}]}
    offender: [{pid,<0.495.0>},
               {id,undefined},
               {mfargs,{ejabberd_http,start_link,undefined}},
               {restart_type,temporary},
               {significant,false},
               {shutdown,5000},
               {child_type,worker}]

Bug description

It looks like analyze_ip_xff expects the first argument to be of the form {IPAdress, Port} (which is the case for TCP connections), but it’s wrong for Unix connections : the first argument is {local, <<>>}. Adding a ip_to_list(local) -> <<"unix">>; clause to misc.erl seems to fix the issue (and can probably replace the ip_to_list({local, _}) clause).

@badlop badlop added this to the ejabberd 22.xx milestone Sep 6, 2022
@badlop
Copy link
Member

badlop commented Sep 6, 2022

Thanks for reporting!

As you noticed, it seems the problem was introduced when support for unix socket was added in that function in e937ff6, but this case was not considered.

(and can probably replace the ip_to_list({local, _}) clause)

I don't think so, as misc:ip_to_list is said to support Ip and the tuple {Ip, Port}

@sloonz
Copy link
Author

sloonz commented Sep 6, 2022

I don't think so, as misc:ip_to_list is said to support Ip and the tuple {Ip, Port}

Doesn’t ip_to_list({IP, _Port}) -> ip_to_list(IP); already covers that ?

@badlop
Copy link
Member

badlop commented Sep 6, 2022

Oops, you're right! 🤦‍♂️ I'll simplify it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants