Skip to content

Commit 61ae599

Browse files
committed
Merge from mysql-5.5-security to mysql-trunk-security.
2 parents daa5e69 + 152bb4c commit 61ae599

12 files changed

Lines changed: 174 additions & 15 deletions

File tree

include/my_base.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
GNU General Public License for more details.
1111
1212
You should have received a copy of the GNU General Public License
13-
along with this program; if not, write to the Free Software
14-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
13+
along with this program; if not, write to the Free Software Foundation,
14+
Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15+
1516

1617
/* This file includes constants used with all databases */
1718

@@ -451,7 +452,8 @@ enum ha_base_keytype {
451452
#define HA_ERR_INDEX_CORRUPT 180 /* InnoDB index corrupted */
452453
#define HA_ERR_UNDO_REC_TOO_BIG 181 /* Undo log record too big */
453454
#define HA_FTS_INVALID_DOCID 182 /* Invalid InnoDB Doc ID */
454-
#define HA_ERR_LAST 182 /* Copy of last error nr */
455+
#define HA_ERR_TABLE_IN_FK_CHECK 183 /* Table being used in foreign key check */
456+
#define HA_ERR_LAST 183 /* Copy of last error nr */
455457

456458
/* Number of different errors */
457459
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
SET DEBUG_SYNC='reset';
2+
create table t1 (f1 integer, key k1 (f1)) engine=innodb;
3+
create table t2 (f1 int, f2 int, key(f1), key(f2)) engine=innodb;
4+
create table t3 (f2 int, key(f2)) engine=innodb;
5+
insert into t1 values (10);
6+
insert into t2 values (10, 20);
7+
insert into t3 values (20);
8+
alter table t2 add constraint c1 foreign key (f1)
9+
references t1(f1) on update cascade;
10+
show create table t1;
11+
Table Create Table
12+
t1 CREATE TABLE `t1` (
13+
`f1` int(11) DEFAULT NULL,
14+
KEY `k1` (`f1`)
15+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
16+
show create table t2;
17+
Table Create Table
18+
t2 CREATE TABLE `t2` (
19+
`f1` int(11) DEFAULT NULL,
20+
`f2` int(11) DEFAULT NULL,
21+
KEY `f1` (`f1`),
22+
KEY `f2` (`f2`),
23+
CONSTRAINT `c1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE
24+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
25+
show create table t3;
26+
Table Create Table
27+
t3 CREATE TABLE `t3` (
28+
`f2` int(11) DEFAULT NULL,
29+
KEY `f2` (`f2`)
30+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
31+
SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL update_can_proceed
32+
WAIT_FOR dict_unfreeze';
33+
alter table t2 add constraint z1 foreign key (f2)
34+
references t3(f2) on update cascade;
35+
SET DEBUG_SYNC='innodb_row_update_for_mysql_begin
36+
WAIT_FOR update_can_proceed';
37+
SET DEBUG_SYNC='innodb_dml_cascade_dict_unfreeze SIGNAL dict_unfreeze
38+
WAIT_FOR foreign_free_cache';
39+
update ignore t1 set f1 = 20;
40+
ERROR HY000: Error on rename of './test/t2' to '#sql2-temporary' (errno: 183 - Table is being used in foreign key check)
41+
SET DEBUG_SYNC='now SIGNAL foreign_free_cache';
42+
drop table t2;
43+
drop table t1;
44+
drop table t3;
45+
SET DEBUG_SYNC='reset';
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
--source include/have_innodb.inc
2+
--source include/have_debug_sync.inc
3+
--source include/not_embedded.inc
4+
5+
SET DEBUG_SYNC='reset';
6+
7+
# Save the initial number of concurrent sessions
8+
--source include/count_sessions.inc
9+
10+
create table t1 (f1 integer, key k1 (f1)) engine=innodb;
11+
create table t2 (f1 int, f2 int, key(f1), key(f2)) engine=innodb;
12+
create table t3 (f2 int, key(f2)) engine=innodb;
13+
14+
insert into t1 values (10);
15+
insert into t2 values (10, 20);
16+
insert into t3 values (20);
17+
18+
alter table t2 add constraint c1 foreign key (f1)
19+
references t1(f1) on update cascade;
20+
21+
show create table t1;
22+
show create table t2;
23+
show create table t3;
24+
25+
SET DEBUG_SYNC='innodb_rename_table_ready SIGNAL update_can_proceed
26+
WAIT_FOR dict_unfreeze';
27+
28+
--send
29+
alter table t2 add constraint z1 foreign key (f2)
30+
references t3(f2) on update cascade;
31+
32+
connect (thr2,localhost,root,,);
33+
connection thr2;
34+
35+
SET DEBUG_SYNC='innodb_row_update_for_mysql_begin
36+
WAIT_FOR update_can_proceed';
37+
SET DEBUG_SYNC='innodb_dml_cascade_dict_unfreeze SIGNAL dict_unfreeze
38+
WAIT_FOR foreign_free_cache';
39+
40+
--send
41+
update ignore t1 set f1 = 20;
42+
43+
connection default;
44+
--replace_regex /'[^']*test\/#sql2-[0-9a-f-]*'/'#sql2-temporary'/
45+
--error ER_ERROR_ON_RENAME
46+
reap;
47+
48+
SET DEBUG_SYNC='now SIGNAL foreign_free_cache';
49+
50+
connection thr2;
51+
reap;
52+
disconnect thr2;
53+
--source include/wait_until_disconnected.inc
54+
55+
connection default;
56+
57+
drop table t2;
58+
drop table t1;
59+
drop table t3;
60+
61+
# Wait till we reached the initial number of concurrent sessions
62+
--source include/wait_until_count_sessions.inc
63+
64+
SET DEBUG_SYNC='reset';

mysys/my_handler_errors.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MYSYS_MY_HANDLER_ERRORS_INCLUDED
22
#define MYSYS_MY_HANDLER_ERRORS_INCLUDED
33

4-
/* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -13,8 +13,8 @@
1313
GNU General Public License for more details.
1414
1515
You should have received a copy of the GNU General Public License
16-
along with this program; if not, write to the Free Software
17-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16+
along with this program; if not, write to the Free Software Foundation,
17+
Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
1818

1919
/*
2020
Errors a handler can give you
@@ -85,7 +85,8 @@ static const char *handler_error_messages[]=
8585
"Index column length exceeds limit",
8686
"Index corrupted",
8787
"Undo record too big",
88-
"Invalid InnoDB FTS Doc ID"
88+
"Invalid InnoDB FTS Doc ID",
89+
"Table is being used in foreign key check"
8990
};
9091

9192
extern void my_handler_error_register(void);

sql/handler.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -10,8 +10,8 @@
1010
GNU General Public License for more details.
1111
1212
You should have received a copy of the GNU General Public License
13-
along with this program; if not, write to the Free Software
14-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
13+
along with this program; if not, write to the Free Software Foundation,
14+
Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
1515

1616
/** @file handler.cc
1717
@@ -405,6 +405,7 @@ int ha_init_errors(void)
405405
SETMSG(HA_ERR_INDEX_COL_TOO_LONG, ER_DEFAULT(ER_INDEX_COLUMN_TOO_LONG));
406406
SETMSG(HA_ERR_INDEX_CORRUPT, ER_DEFAULT(ER_INDEX_CORRUPT));
407407
SETMSG(HA_FTS_INVALID_DOCID, "Invalid InnoDB FTS Doc ID");
408+
SETMSG(HA_ERR_TABLE_IN_FK_CHECK, ER_DEFAULT(ER_TABLE_IN_FK_CHECK));
408409

409410
/* Register the error messages for use with my_error(). */
410411
return my_error_register(get_handler_errmsgs, HA_ERR_FIRST, HA_ERR_LAST);
@@ -3112,6 +3113,9 @@ void handler::print_error(int error, myf errflag)
31123113
case HA_ERR_UNDO_REC_TOO_BIG:
31133114
textno= ER_UNDO_RECORD_TOO_BIG;
31143115
break;
3116+
case HA_ERR_TABLE_IN_FK_CHECK:
3117+
textno= ER_TABLE_IN_FK_CHECK;
3118+
break;
31153119
default:
31163120
{
31173121
/* The error was "unknown" to this function.

sql/share/errmsg-utf8.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6631,4 +6631,5 @@ ER_BINLOG_UNSAFE_WRITE_AUTOINC_SELECT
66316631
ER_BINLOG_UNSAFE_CREATE_SELECT_AUTOINC
66326632
eng "CREATE TABLE... SELECT... on a table with an auto-increment column is unsafe because the order in which rows are retrieved by the SELECT determines which (if any) rows are inserted. This order cannot be predicted and may differ on master and the slave."
66336633

6634-
6634+
ER_TABLE_IN_FK_CHECK
6635+
eng "Table is being used in foreign key check."

storage/innobase/dict/dict0dict.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -64,6 +64,8 @@ UNIV_INTERN dict_index_t* dict_ind_compact;
6464
#include "lock0lock.h"
6565
#include "dict0priv.h"
6666
#include "row0upd.h"
67+
#include "m_string.h"
68+
#include "my_sys.h"
6769

6870
#include <ctype.h>
6971

@@ -2892,6 +2894,8 @@ dict_foreign_free(
28922894
/*==============*/
28932895
dict_foreign_t* foreign) /*!< in, own: foreign key struct */
28942896
{
2897+
ut_a(foreign->foreign_table->n_foreign_key_checks_running == 0);
2898+
28952899
mem_heap_free(foreign->heap);
28962900
}
28972901

storage/innobase/handler/ha_innodb.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,9 @@ convert_error_code_to_mysql(
13201320
case DB_OUT_OF_FILE_SPACE:
13211321
return(HA_ERR_RECORD_FILE_FULL);
13221322

1323+
case DB_TABLE_IN_FK_CHECK:
1324+
return(HA_ERR_TABLE_IN_FK_CHECK);
1325+
13231326
case DB_TABLE_IS_BEING_USED:
13241327
return(HA_ERR_WRONG_COMMAND);
13251328

@@ -9383,6 +9386,8 @@ innobase_rename_table(
93839386
normalize_table_name(norm_to, to);
93849387
normalize_table_name(norm_from, from);
93859388

9389+
DEBUG_SYNC_C("innodb_rename_table_ready");
9390+
93869391
/* Serialize data dictionary operations with dictionary mutex:
93879392
no deadlocks can occur then in these operations */
93889393

storage/innobase/include/db0err.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
3+
Copyright (c) 1996, 2012, Oracle and/or its affiliates. All Rights Reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License as published by the Free Software
@@ -115,6 +115,8 @@ enum db_err {
115115
DB_READ_ONLY, /*!< Update operation attempted in
116116
a read-only transaction */
117117
DB_FTS_INVALID_DOCID, /* FTS Doc ID cannot be zero */
118+
DB_TABLE_IN_FK_CHECK, /* table is being used in foreign
119+
key check */
118120

119121
/* The following are partial failure codes */
120122
DB_FAIL = 1000,

storage/innobase/row/row0ins.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Created 4/20/1996 Heikki Tuuri
5151
#include "buf0lru.h"
5252
#include "fts0fts.h"
5353
#include "fts0types.h"
54+
#include "m_string.h"
55+
#include "my_sys.h"
5456

5557
/*************************************************************************
5658
IMPORTANT NOTE: Any operation that generates redo MUST check that there
@@ -1241,6 +1243,9 @@ row_ins_foreign_check_on_constraint(
12411243
release the latch. */
12421244

12431245
row_mysql_unfreeze_data_dictionary(thr_get_trx(thr));
1246+
1247+
DEBUG_SYNC_C("innodb_dml_cascade_dict_unfreeze");
1248+
12441249
row_mysql_freeze_data_dictionary(thr_get_trx(thr));
12451250

12461251
mtr_start(mtr);

0 commit comments

Comments
 (0)