MDEV-34716 Fix mysql.servers socket max length too short

The limit of socket length on unix according to libc is 108, see
sockaddr_un::sun_path, but in the table it is a string of max length
64, which results in truncation of socket and failure to connect by
plugins using servers such as spider.
This commit is contained in:
Yuchen Pei 2024-12-17 10:40:57 +11:00
parent bc6121819c
commit 77c9917663
No known key found for this signature in database
GPG key ID: 3DD1B35105743563
16 changed files with 88 additions and 14 deletions

View file

@ -3,7 +3,7 @@
@@ -442,7 +442,7 @@
mysql.time_zone_transition 3895294076
mysql.plugin 0
mysql.servers 2783974349
mysql.servers 4154392229
-mysql.func 3241572444
+mysql.func 310494789
mysql.innodb_table_stats 347867921
@ -12,7 +12,7 @@
@@ -477,7 +477,7 @@
mysql.time_zone_transition 3895294076
mysql.plugin 0
mysql.servers 2783974349
mysql.servers 4154392229
-mysql.func 3241572444
+mysql.func 310494789
mysql.innodb_table_stats 347867921

View file

@ -444,7 +444,7 @@ Table Checksum
mysql.roles_mapping 3150178430
mysql.time_zone_transition 3895294076
mysql.plugin 0
mysql.servers 2783974349
mysql.servers 4154392229
mysql.func 3241572444
mysql.innodb_table_stats 347867921
mysql.table_stats 664320059
@ -479,7 +479,7 @@ Table Checksum
mysql.roles_mapping 3150178430
mysql.time_zone_transition 3895294076
mysql.plugin 0
mysql.servers 2783974349
mysql.servers 4154392229
mysql.func 3241572444
mysql.innodb_table_stats 347867921
mysql.table_stats 664320059

View file

@ -24,6 +24,11 @@ SELECT * FROM mysql.servers;
Server_name Host Db Username Password Port Socket Wrapper Owner
s1 3306 bar mysql
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET '/tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock');
SELECT Socket FROM mysql.servers where Server_name = 's1';
Socket
/tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock
DROP SERVER s1;
#
# MDEV-33783 CREATE SERVER segfaults on wrong mysql.servers
#

View file

@ -23,6 +23,10 @@ CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET 'bar');
SELECT * FROM mysql.servers;
DROP SERVER s1;
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET '/tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock');
SELECT Socket FROM mysql.servers where Server_name = 's1';
DROP SERVER s1;
--echo #
--echo # MDEV-33783 CREATE SERVER segfaults on wrong mysql.servers
--echo #

View file

@ -129,7 +129,7 @@ servers CREATE TABLE `servers` (
`Username` char(80) NOT NULL DEFAULT '',
`Password` char(64) NOT NULL DEFAULT '',
`Port` int(4) NOT NULL DEFAULT 0,
`Socket` char(64) NOT NULL DEFAULT '',
`Socket` char(108) NOT NULL DEFAULT '',
`Wrapper` char(64) NOT NULL DEFAULT '',
`Owner` varchar(512) NOT NULL DEFAULT '',
PRIMARY KEY (`Server_name`)

View file

@ -167,7 +167,7 @@ servers CREATE TABLE `servers` (
`Username` char(80) NOT NULL DEFAULT '',
`Password` char(64) NOT NULL DEFAULT '',
`Port` int(4) NOT NULL DEFAULT 0,
`Socket` char(64) NOT NULL DEFAULT '',
`Socket` char(108) NOT NULL DEFAULT '',
`Wrapper` char(64) NOT NULL DEFAULT '',
`Owner` varchar(512) NOT NULL DEFAULT '',
PRIMARY KEY (`Server_name`)

View file

@ -171,7 +171,7 @@ servers CREATE TABLE `servers` (
`Username` char(80) NOT NULL DEFAULT '',
`Password` char(64) NOT NULL DEFAULT '',
`Port` int(4) NOT NULL DEFAULT 0,
`Socket` char(64) NOT NULL DEFAULT '',
`Socket` char(108) NOT NULL DEFAULT '',
`Wrapper` char(64) NOT NULL DEFAULT '',
`Owner` varchar(512) NOT NULL DEFAULT '',
PRIMARY KEY (`Server_name`)

View file

@ -151,7 +151,7 @@ servers CREATE TABLE `servers` (
`Username` char(80) NOT NULL DEFAULT '',
`Password` char(64) NOT NULL DEFAULT '',
`Port` int(4) NOT NULL DEFAULT 0,
`Socket` char(64) NOT NULL DEFAULT '',
`Socket` char(108) NOT NULL DEFAULT '',
`Wrapper` char(64) NOT NULL DEFAULT '',
`Owner` varchar(512) NOT NULL DEFAULT '',
PRIMARY KEY (`Server_name`)

View file

@ -172,7 +172,7 @@ servers CREATE TABLE `servers` (
`Username` char(80) NOT NULL DEFAULT '',
`Password` char(64) NOT NULL DEFAULT '',
`Port` int(4) NOT NULL DEFAULT 0,
`Socket` char(64) NOT NULL DEFAULT '',
`Socket` char(108) NOT NULL DEFAULT '',
`Wrapper` char(64) NOT NULL DEFAULT '',
`Owner` varchar(512) NOT NULL DEFAULT '',
PRIMARY KEY (`Server_name`)

View file

@ -163,7 +163,7 @@ def mysql servers Owner 9 '' NO varchar 512 1536 NULL NULL NULL utf8 utf8_genera
def mysql servers Password 5 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) select,insert,update,references NEVER NULL
def mysql servers Port 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(4) select,insert,update,references NEVER NULL
def mysql servers Server_name 1 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) PRI select,insert,update,references NEVER NULL
def mysql servers Socket 7 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) select,insert,update,references NEVER NULL
def mysql servers Socket 7 '' NO char 108 324 NULL NULL NULL utf8 utf8_general_ci char(108) select,insert,update,references NEVER NULL
def mysql servers Username 4 '' NO char 80 240 NULL NULL NULL utf8 utf8_general_ci char(80) select,insert,update,references NEVER NULL
def mysql servers Wrapper 8 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) select,insert,update,references NEVER NULL
def mysql slow_log db 7 NULL NO varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) select,insert,update,references NEVER NULL
@ -490,7 +490,7 @@ NULL mysql proxies_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql servers Username char 80 240 utf8 utf8_general_ci char(80)
3.0000 mysql servers Password char 64 192 utf8 utf8_general_ci char(64)
NULL mysql servers Port int NULL NULL NULL NULL int(4)
3.0000 mysql servers Socket char 64 192 utf8 utf8_general_ci char(64)
3.0000 mysql servers Socket char 108 324 utf8 utf8_general_ci char(108)
3.0000 mysql servers Wrapper char 64 192 utf8 utf8_general_ci char(64)
3.0000 mysql servers Owner varchar 512 1536 utf8 utf8_general_ci varchar(512)
NULL mysql slow_log start_time timestamp NULL NULL NULL NULL timestamp(6)

View file

@ -149,7 +149,7 @@ def mysql servers Owner 9 '' NO varchar 512 1536 NULL NULL NULL utf8 utf8_genera
def mysql servers Password 5 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) NEVER NULL
def mysql servers Port 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(4) NEVER NULL
def mysql servers Server_name 1 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) PRI NEVER NULL
def mysql servers Socket 7 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) NEVER NULL
def mysql servers Socket 7 '' NO char 108 324 NULL NULL NULL utf8 utf8_general_ci char(108) NEVER NULL
def mysql servers Username 4 '' NO char 80 240 NULL NULL NULL utf8 utf8_general_ci char(80) NEVER NULL
def mysql servers Wrapper 8 '' NO char 64 192 NULL NULL NULL utf8 utf8_general_ci char(64) NEVER NULL
def mysql slow_log db 7 NULL NO varchar 512 1536 NULL NULL NULL utf8 utf8_general_ci varchar(512) NEVER NULL
@ -473,7 +473,7 @@ NULL mysql proxies_priv Timestamp timestamp NULL NULL NULL NULL timestamp
3.0000 mysql servers Username char 80 240 utf8 utf8_general_ci char(80)
3.0000 mysql servers Password char 64 192 utf8 utf8_general_ci char(64)
NULL mysql servers Port int NULL NULL NULL NULL int(4)
3.0000 mysql servers Socket char 64 192 utf8 utf8_general_ci char(64)
3.0000 mysql servers Socket char 108 324 utf8 utf8_general_ci char(108)
3.0000 mysql servers Wrapper char 64 192 utf8 utf8_general_ci char(64)
3.0000 mysql servers Owner varchar 512 1536 utf8 utf8_general_ci varchar(512)
NULL mysql slow_log start_time timestamp NULL NULL NULL NULL timestamp(6)

View file

@ -108,7 +108,7 @@ CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret
CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=Aria transactional=1 CHARACTER SET utf8 COLLATE utf8_general_ci comment='MySQL plugins';
CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host varchar(2048) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(80) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) engine=Aria transactional=1 CHARACTER SET utf8 comment='MySQL Foreign Servers table';
CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host varchar(2048) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(80) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(108) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) engine=Aria transactional=1 CHARACTER SET utf8 comment='MySQL Foreign Servers table';
CREATE TABLE IF NOT EXISTS tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(141) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger','Delete versioning rows') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=Aria transactional=1 CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges';

View file

@ -851,3 +851,7 @@ DELIMITER ;
ALTER TABLE servers
MODIFY Host varchar(2048) NOT NULL DEFAULT '',
MODIFY Owner varchar(512) NOT NULL DEFAULT '';
# MDEV-34716 Fix mysql.servers socket max length too short
ALTER TABLE servers
MODIFY Socket char(108) NOT NULL DEFAULT '';

View file

@ -0,0 +1,29 @@
for master_1
for child2
for child3
set spider_same_server_link= 1;
CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
select Socket from mysql.servers where Server_name = "srv";
Socket
/tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock
create table t2 (c int);
alter SERVER srv OPTIONS (DATABASE 'test');
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
insert into t1 values (1), (2), (3);
select * from t1;
c
1
2
3
select * from t2;
c
1
2
3
drop table t1, t2;
drop server srv;
for master_1
for child2
for child3

View file

@ -0,0 +1,5 @@
[mysqld.1.1]
socket= /tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock
[ENV]
MASTER_1_MYSOCK= @mysqld.1.1.socket

View file

@ -0,0 +1,27 @@
--disable_query_log
--disable_result_log
--source test_init.inc
--enable_result_log
--enable_query_log
set spider_same_server_link= 1;
# Test long socket length
evalp CREATE SERVER srv FOREIGN DATA WRAPPER mysql
OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
select Socket from mysql.servers where Server_name = "srv";
create table t2 (c int);
# triggers a table read into the server object
alter SERVER srv OPTIONS (DATABASE 'test');
create table t1 (c int) ENGINE=Spider
COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
insert into t1 values (1), (2), (3);
select * from t1;
select * from t2;
drop table t1, t2;
drop server srv;
--disable_query_log
--disable_result_log
--source test_deinit.inc
--enable_result_log
--enable_query_log