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

acl query sql contain multiple '%u' variable will cause system error #2937

Closed
JinXin1995 opened this issue Sep 26, 2019 · 4 comments
Assignees
Labels
BUG
Milestone

Comments

@JinXin1995
Copy link

@JinXin1995 JinXin1995 commented Sep 26, 2019

Environment

  • OS: docker
  • EMQ: 3.2.3

Description

plugin: emqx_auth_pgsql

sql:

select allow, ipaddr, username, clientid, access, topic
from (
(select allow, ipaddr, username, clientid, access, topic from t_mqtt_acl where ipaddr = '%a' or username = '%u' or username = '$all' or clientid = '%c')
union
(select model.allow as allow, null as ipaddr, '%u' as username, null as clientid, model.access as access, replace(model.topic, '{sn}', '%u') as topic from t_mqtt_acl_for_product as model, t_platform_device as device where device.product_id=model.product_id and device.device_sn='%u')) as t

log:

2019-09-26 09:12:15.949 [error] 8587fcee725d48bc9b6e34da0df1ba00@192.168.1.122:56070 ** State machine <0.3997.0> terminating
** Last event = {cast,
                    {incoming,
                        {mqtt_packet,
                            {mqtt_packet_header,8,false,1,false},
                            {mqtt_packet_subscribe,1,undefined,
                                [{<<"/test/1">>,
                                  #{nl => 0,qos => 0,rap => 0,rc => 0,
                                    rh => 0}}]},
                            undefined}}}
** When server state  = {connected,
                            {state,esockd_transport,#Port<0.509>,
                                {{192,168,1,122},56070},
                                undefined,running,100,
                                {pstate,external,
                                    #Fun<emqx_channel.0.11313496>,
                                    {{172,18,0,8},1883},
                                    {{192,168,1,122},56070},
                                    nossl,4,<<"MQTT">>,
                                    <<"8587fcee725d48bc9b6e34da0df1ba00">>,
                                    false,<0.3997.0>,undefined,undefined,
                                    <<"platform">>,<0.3999.0>,true,#{},
                                    undefined,undefined,60,false,
                                    #{msg => 0,pkt => 1},
                                    #{msg => 0,pkt => 1},
                                    true,
                                    {1569,489135,284858},
                                    #{from_client => 0,to_client => 0},
                                    emqx_channel,
                                    #{anonymous => false,
                                      auth_result => success,
                                      client_id =>
                                          <<"8587fcee725d48bc9b6e34da0df1ba00">>,
                                      is_superuser => false,
                                      mountpoint => undefined,
                                      peername => {{192,168,1,122},56070},
                                      sockname => {{172,18,0,8},1883},
                                      username => <<"platform">>,
                                      ws_cookie => undefined,zone => external},
                                    undefined},
                                {none,#{max_size => 1048576,version => 4}},
                                {emqx_gc,
                                    #{cnt => {1000,998},
                                      oct => {1048576,1048484}}},
                                {keepalive,#Fun<emqx_channel.3.11313496>,78,
                                    45,
                                    {keepalive,check},
                                    #Ref<0.2152744048.3831496707.103036>,0},
                                undefined,undefined,undefined,true,
                                #Ref<0.2152744048.3831496705.138041>,15000}}
** Reason for termination = error:function_clause
** Callback mode = [state_functions,state_enter]
** Stacktrace =
**  [{lists,zip,[[],[<<"platform">>]],[{file,"lists.erl"},{line,387}]},
     {lists,zip,2,[{file,"lists.erl"},{line,387}]},
     {lists,zip,2,[{file,"lists.erl"},{line,387}]},
     {epgsql,prepared_query,3,
             [{file,"/emqx_rel/_checkouts/epgsql/src/epgsql.erl"},{line,257}]},
     {emqx_acl_pgsql,do_check_acl,5,
                     [{file,"/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl"},
                      {line,40}]},
     {emqx_acl_pgsql,check_acl,5,
                     [{file,"/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl"},
                      {line,31}]},
     {emqx_hooks,do_run_fold,3,
                 [{file,"/emqx_rel/_checkouts/emqx/src/emqx_hooks.erl"},
                  {line,131}]},
     {emqx_access_control,do_check_acl,3,
                          [{file,"/emqx_rel/_checkouts/emqx/src/emqx_access_control.erl"},
                           {line,59}]}]
2019-09-26 09:12:15.962 [error] 8587fcee725d48bc9b6e34da0df1ba00@192.168.1.122:56070 crasher:
    initial call: emqx_channel:init/1
    pid: <0.3997.0>
    registered_name: []
    exception error: no function clause matching 
                     lists:zip([],[<<"platform">>]) (lists.erl, line 387)
      in function  lists:zip/2 (lists.erl, line 387)
      in call from lists:zip/2 (lists.erl, line 387)
      in call from epgsql:prepared_query/3 (/emqx_rel/_checkouts/epgsql/src/epgsql.erl, line 257)
      in call from emqx_acl_pgsql:do_check_acl/5 (/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl, line 40)
      in call from emqx_acl_pgsql:check_acl/5 (/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl, line 31)
      in call from emqx_hooks:do_run_fold/3 (/emqx_rel/_checkouts/emqx/src/emqx_hooks.erl, line 131)
      in call from emqx_access_control:do_check_acl/3 (/emqx_rel/_checkouts/emqx/src/emqx_access_control.erl, line 59)
    ancestors: [<0.1666.0>,<0.1665.0>,esockd_sup,<0.1354.0>]
    message_queue_len: 1
    messages: [{'EXIT',#Port<0.509>,normal}]
    links: [<0.3999.0>,<0.1666.0>]
    dictionary: [{rand_seed,
                      {#{bits => 58,jump => #Fun<rand.8.10897371>,
                         next => #Fun<rand.5.10897371>,type => exrop,
                         uniform => #Fun<rand.6.10897371>,
                         uniform_n => #Fun<rand.7.10897371>,
                         weak_low_bits => 1},
                       [192096854773522229|100130951213011219]}},
                  {force_shutdown_policy,
                      #{max_heap_size => 838860800,message_queue_len => 8000}},
                  {guid,{1569489135949004,7876970024861,1}},
                  {incoming_bytes,92},
                  {'$logger_metadata$',
                      #{client_id => <<"8587fcee725d48bc9b6e34da0df1ba00">>,
                        peername => "192.168.1.122:56070"}}]
    trap_exit: true
    status: running
    heap_size: 17731
    stack_size: 27
    reductions: 389933
  neighbours:
2019-09-26 09:12:15.962 [error] supervisor: 'esockd_connection_sup - <0.1666.0>'
    errorContext: connection_crashed
    reason: {function_clause,
                [{lists,zip,
                     [[],[<<"platform">>]],
                     [{file,"lists.erl"},{line,387}]},
                 {lists,zip,2,[{file,"lists.erl"},{line,387}]},
                 {lists,zip,2,[{file,"lists.erl"},{line,387}]},
                 {epgsql,prepared_query,3,
                     [{file,"/emqx_rel/_checkouts/epgsql/src/epgsql.erl"},
                      {line,257}]},
                 {emqx_acl_pgsql,do_check_acl,5,
                     [{file,
                          "/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl"},
                      {line,40}]},
                 {emqx_acl_pgsql,check_acl,5,
                     [{file,
                          "/emqx_rel/_checkouts/emqx_auth_pgsql/src/emqx_acl_pgsql.erl"},
                      {line,31}]},
                 {emqx_hooks,do_run_fold,3,
                     [{file,"/emqx_rel/_checkouts/emqx/src/emqx_hooks.erl"},
                      {line,131}]},
                 {emqx_access_control,do_check_acl,3,
                     [{file,
                          "/emqx_rel/_checkouts/emqx/src/emqx_access_control.erl"},
                      {line,59}]}]}
    offender: [{pid,<0.3997.0>},
               {name,connection},
               {mfargs,{emqx_channel,start_link,
                                     [[{deflate_options,[]},
                                       {max_conn_rate,1000},
                                       {active_n,100},
                                       {zone,external}]]}}]
@turtleDeng

This comment has been minimized.

Copy link
Collaborator

@turtleDeng turtleDeng commented Sep 26, 2019

Please provide a detailed table structure and configuration file.

@turtleDeng turtleDeng added the Support label Sep 26, 2019
@turtleDeng turtleDeng added this to the 4.0.0 milestone Sep 26, 2019
@JinXin1995

This comment has been minimized.

Copy link
Author

@JinXin1995 JinXin1995 commented Sep 26, 2019

@HJianBo

This comment has been minimized.

Copy link
Member

@HJianBo HJianBo commented Oct 2, 2019

Hi, @JinXin1995 It's a bug actually. I have fixed it, you will see at next version

Thanks for your report that :)

@HJianBo HJianBo added BUG and removed Support labels Oct 2, 2019
@turtleDeng

This comment has been minimized.

Copy link
Collaborator

@turtleDeng turtleDeng commented Oct 29, 2019

Thanks for your feedback, we have fixed it in v3.2.4.

@turtleDeng turtleDeng closed this Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.