Skip to content

Commit a134f1e

Browse files
an3lcvicentiu
authored andcommitted
PR #1127 and PR #1150
PR#1127: Fix is_check_constraints.result to be compatibile with 10.3 The patch is done according to the original patch for MDEV-14474 1edd09c and not one which is merged on server d526679. This patch includes: - Rename from `is_check_constraint` to `is_check_constraints` to tests and results - Per review, change the order of fields in IS check_constraints table by adding the column `table_name` before `constraint_name`. According to the standard 2006 there is no `table_name` column. - Original patch and one in `10.3` supports embedded server this patch doesn't support. After the merge `10.3` will not support also. - Don't use patch c8b8b01 to change the length of `CHECK_CLAUSE` field PR#1150: MDEV-18440: Information_schema.check_constraints possible data leak This patch is extension of PR 1127 and includes: - Check for table grants - Additional test according to the MDEV specification
1 parent f0aa073 commit a134f1e

File tree

3 files changed

+83
-13
lines changed

3 files changed

+83
-13
lines changed

mysql-test/suite/funcs_1/r/is_check_constraint.result renamed to mysql-test/suite/funcs_1/r/is_check_constraints.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,29 @@ disconnect con1;
119119
connection default;
120120
DROP USER boo1;
121121
DROP USER boo2;
122+
#
123+
# MDEV-18440: Information_schema.check_constraints possible data leak
124+
#
125+
CREATE USER foo;
126+
CREATE DATABASE db;
127+
USE db;
128+
CREATE TABLE t1 (a int, b int, CONSTRAINT CHECK (b > 0));
129+
INSERT INTO t1 VALUES (1, 2), (2, 3);
130+
GRANT SELECT (a) ON t1 TO foo;
131+
SHOW GRANTS FOR foo;
132+
Grants for foo@%
133+
GRANT USAGE ON *.* TO 'foo'@'%'
134+
GRANT SELECT (a) ON `db`.`t1` TO 'foo'@'%'
135+
SELECT * FROM information_schema.check_constraints;
136+
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
137+
def db t1 CONSTRAINT_1 `b` > 0
138+
CONNECT con1,localhost, foo,, db;
139+
SELECT a FROM t1;
140+
a
141+
1
142+
2
143+
SELECT * FROM information_schema.check_constraints;
144+
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
145+
connection default;
146+
DROP USER foo;
147+
DROP DATABASE db;

mysql-test/suite/funcs_1/t/is_check_constraint.test renamed to mysql-test/suite/funcs_1/t/is_check_constraints.test

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CREATE TABLE t1
4040
CONSTRAINT CHECK (tt > 32), CONSTRAINT CHECK (tt <50),# autogenerated names table constraints
4141
CONSTRAINT CHK_tt CHECK(tt<100) # named table constraint
4242
) ENGINE=InnoDB;
43-
--sorted_result
43+
--sorted_result
4444
SELECT * from information_schema.check_constraints;
4545

4646
ALTER TABLE t1
@@ -55,7 +55,7 @@ start_date DATE,
5555
end_date DATE,
5656
CONSTRAINT CHK_dates CHECK(start_date IS NULL) #table constraint
5757
)ENGINE=Innodb;
58-
--sorted_result
58+
--sorted_result
5959
SELECT * from information_schema.check_constraints;
6060

6161
ALTER TABLE t1
@@ -70,12 +70,12 @@ a int,
7070
b int check (b>0), # field constraint named 'b'
7171
CONSTRAINT b check (b>10) # table constraint
7272
) ENGINE=InnoDB;
73-
--sorted_result
73+
--sorted_result
7474
SELECT * from information_schema.check_constraints;
7575

7676
DISCONNECT con1;
7777
CONNECT(con2, localhost, boo2,, test);
78-
--sorted_result
78+
--sorted_result
7979
SELECT * from information_schema.check_constraints;
8080

8181
DISCONNECT con2;
@@ -90,3 +90,28 @@ DISCONNECT con1;
9090
--CONNECTION default
9191
DROP USER boo1;
9292
DROP USER boo2;
93+
94+
--echo #
95+
--echo # MDEV-18440: Information_schema.check_constraints possible data leak
96+
--echo #
97+
98+
CREATE USER foo;
99+
CREATE DATABASE db;
100+
USE db;
101+
CREATE TABLE t1 (a int, b int, CONSTRAINT CHECK (b > 0));
102+
INSERT INTO t1 VALUES (1, 2), (2, 3);
103+
GRANT SELECT (a) ON t1 TO foo;
104+
105+
SHOW GRANTS FOR foo;
106+
--sorted_result
107+
SELECT * FROM information_schema.check_constraints;
108+
109+
CONNECT(con1,localhost, foo,, db);
110+
SELECT a FROM t1;
111+
--sorted_result
112+
SELECT * FROM information_schema.check_constraints;
113+
114+
--CONNECTION default
115+
116+
DROP USER foo;
117+
DROP DATABASE db;

sql/sql_show.cc

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6526,7 +6526,7 @@ static int get_check_constraints_record(THD *thd, TABLE_LIST *tables,
65266526
LEX_STRING *table_name)
65276527
{
65286528
DBUG_ENTER("get_check_constraints_record");
6529-
if(res)
6529+
if (res)
65306530
{
65316531
if (thd->is_error())
65326532
push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
@@ -6535,24 +6535,40 @@ static int get_check_constraints_record(THD *thd, TABLE_LIST *tables,
65356535
thd->clear_error();
65366536
DBUG_RETURN(0);
65376537
}
6538-
if(!tables->view)
6538+
if (!tables->view)
65396539
{
65406540
StringBuffer<MAX_FIELD_WIDTH> str(system_charset_info);
6541+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
6542+
TABLE_LIST table_acl_check;
6543+
bzero((char*) &table_acl_check, sizeof(table_acl_check));
6544+
#endif
65416545
for (uint i= 0; i < tables->table->s->table_check_constraints; i++)
65426546
{
6547+
#ifndef NO_EMBEDDED_ACCESS_CHECKS
6548+
if (!(thd->col_access & TABLE_ACLS))
6549+
{
6550+
table_acl_check.db= db_name->str;
6551+
table_acl_check.db_length= db_name->length;
6552+
table_acl_check.table_name= table_name->str;
6553+
table_acl_check.table_name_length= table_name->length;
6554+
table_acl_check.grant.privilege= thd->col_access;
6555+
if (check_grant(thd, TABLE_ACLS, &table_acl_check, FALSE, 1, TRUE))
6556+
continue;
6557+
}
6558+
#endif
65436559
Virtual_column_info *check= tables->table->check_constraints[i];
65446560
table->field[0]->store(STRING_WITH_LEN("def"), system_charset_info);
65456561
table->field[3]->store(check->name.str, check->name.length,
65466562
system_charset_info);
6563+
/* Make sure the string is empty between each print. */
65476564
str.length(0);
65486565
check->print(&str);
65496566
table->field[4]->store(str.ptr(), str.length(), system_charset_info);
65506567
if (schema_table_store_record(thd, table))
65516568
DBUG_RETURN(1);
65526569
}
65536570
}
6554-
6555-
DBUG_RETURN(0);
6571+
DBUG_RETURN(res);
65566572
}
65576573

65586574
static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
@@ -9370,11 +9386,14 @@ ST_FIELD_INFO spatial_ref_sys_fields_info[]=
93709386
ST_FIELD_INFO check_constraints_fields_info[]=
93719387
{
93729388
{"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
9373-
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
9389+
{"CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
9390+
OPEN_FULL_TABLE},
93749391
{"TABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
9375-
{"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
9376-
{"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
9377-
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE }
9392+
{"CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
9393+
OPEN_FULL_TABLE},
9394+
{"CHECK_CLAUSE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
9395+
OPEN_FULL_TABLE},
9396+
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}
93789397
};
93799398

93809399
/*
@@ -9393,7 +9412,7 @@ ST_SCHEMA_TABLE schema_tables[]=
93939412
{"CHARACTER_SETS", charsets_fields_info, 0,
93949413
fill_schema_charsets, make_character_sets_old_format, 0, -1, -1, 0, 0},
93959414
{"CHECK_CONSTRAINTS", check_constraints_fields_info, 0, get_all_tables, 0,
9396-
get_check_constraints_record, 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_TABLE_ONLY},
9415+
get_check_constraints_record, 1, 2, 0, OPTIMIZE_I_S_TABLE|OPEN_TABLE_ONLY},
93979416
{"COLLATIONS", collation_fields_info, 0,
93989417
fill_schema_collation, make_old_format, 0, -1, -1, 0, 0},
93999418
{"COLLATION_CHARACTER_SET_APPLICABILITY", coll_charset_app_fields_info,

0 commit comments

Comments
 (0)