[MXS-681] Loading service users error Created: 2016-04-21  Updated: 2016-04-21  Resolved: 2016-04-21

Status: Closed
Project: MariaDB MaxScale
Component/s: Core
Affects Version/s: 1.4.1
Fix Version/s: 1.4.2

Type: Bug Priority: Major
Reporter: Onno Steenbergen Assignee: markus makela
Resolution: Fixed Votes: 0
Labels: None
Environment:

Debian GNU/Linux 8.2 (jessie)
MaxScale 1.4.1
MySQL 5.7.12-log


Attachments: File mariadb.log    

 Description   

After a installing MaxScale on a freshly installed VM using the default config (expect server locations) it fails with the following error in the log:

2016-04-21 12:24:48 debug : Dbusers : Loading data from backend database with Master role [10.0.3.26:3306] for service [Read-Write Service]
2016-04-21 12:24:48 error : Loading users for service [Read-Write Service] encountered error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'B' at line 1].

MaxScale doesn't log internal queries so I used tcpdump to capture the query

13:24:55.798079 IP 10.0.3.16.52185 > 10.0.3.26.3306: Flags [P.], seq 2183529305:2183529981, ack 3775999896, win 229, options [nop,nop,TS val 42627172 ecr 42101003], length 676
E...r.@.@...
...
........&.Y../............
..pd..i......SELECT COUNT(1) AS nusers_db FROM (SELECT DISTINCT user.user AS user, user.host AS host, user.authentication_string AS password, concat(user.user,user.host,user.authentication_string, IF((user.Select_priv+0)||find_in_set('Select',Coalesce(tp.Table_priv,0)),'Y','N') , COALESCE( db.db,tp.db, '')) AS userdata, user.Select_priv AS anydb, COALESCE( db.db,tp.db, NULL) AS db FROM mysql.user LEFT JOIN mysql.db ON user.user=db.user AND user.host=db.host LEFT JOIN mysql.tables_priv tp ON user.user=tp.user AND user.host=tp.host WHERE user.user IS NOT NULL AND user.user <> '' AND user.user NOT IN ('root') ORDER B

13:24:55.798440 IP 10.0.3.26.3306 > 10.0.3.16.52185: Flags [P.], seq 3775999896:3776000056, ack 2183529981, win 246, options [nop,nop,TS val 42101003 ecr 42627172], length 160
E...F3@.@...
...
........./..&.............
..i...pd.....(.#42000You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'B' at line 1

Looking at the code I think I found the cause in server/core/dbusers.c. It seems that the MAX_QUERY_STR_LEN is incorrect.

The definition is:

/** The maximum possible length of the query */
#define MAX_QUERY_STR_LEN strlen(MYSQL_USERS_COUNT_TEMPLATE_START \
MYSQL_USERS_COUNT_TEMPLATE_END MYSQL_USERS_DB_QUERY_TEMPLATE \
MYSQL_USERS_ORDER_BY) + strlen(MYSQL57_PASSWORD) * 2 + 1

While the code in the get_usercount_query function actually uses:

snprintf(buffer, MAX_QUERY_STR_LEN, MYSQL_USERS_COUNT_TEMPLATE_START
MYSQL_USERS_DB_QUERY_TEMPLATE "%s" MYSQL_USERS_ORDER_BY
MYSQL_USERS_COUNT_TEMPLATE_END, password, password,
include_root ? "" : USERS_QUERY_NO_ROOT);

The USERS_QUERY_NO_ROOT seems to be missing in the MAX_QUERY_STR_LEN.



 Comments   
Comment by markus makela [ 2016-04-21 ]

The USER_QUERY_NO_ROOT was indeed missing and caused the query to be truncated when 5.7 was used and the root user was not fetched.

Generated at Thu Feb 08 04:01:08 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.