Skip to content

Commit 9e1035c

Browse files
BUG#26881798: SERVER EXITS WHEN PRIMARY KEY IN MYSQL.PROC
IS DROPPED ANALYSIS: ========= It is advised not to tamper with the system tables. When primary key is dropped from a system table, certain operations on the table which tries to access the table key information may lead to server exit. FIX: ==== An appropriate error is now reported in such a case.
1 parent ecc5a07 commit 9e1035c

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

sql/event_db_repository.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -174,6 +174,8 @@ class Event_db_intact : public Table_check_intact
174174
error_log_print(ERROR_LEVEL, fmt, args);
175175
va_end(args);
176176
}
177+
public:
178+
Event_db_intact() { has_keys= TRUE; }
177179
};
178180

179181
/** In case of an error, a message is printed to the error log. */

sql/sp.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -351,7 +351,7 @@ class Proc_table_intact : public Table_check_intact
351351
bool m_print_once;
352352

353353
public:
354-
Proc_table_intact() : m_print_once(TRUE) {}
354+
Proc_table_intact() : m_print_once(TRUE) { has_keys= TRUE; }
355355

356356
protected:
357357
void report_error(uint code, const char *fmt, ...);

sql/sql_acl.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, 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
@@ -949,6 +949,8 @@ class Acl_table_intact : public Table_check_intact
949949
va_end(args);
950950
}
951951
}
952+
public:
953+
Acl_table_intact() { has_keys= TRUE; }
952954
};
953955

954956
#define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3)

sql/sql_plugin.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -1899,6 +1899,16 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
18991899
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
19001900
DBUG_RETURN(TRUE);
19011901

1902+
if (!table->key_info)
1903+
{
1904+
my_printf_error(ER_UNKNOWN_ERROR,
1905+
"The table '%s.%s' does not have the necessary key(s) "
1906+
"defined on it. Please check the table definition and "
1907+
"create index(s) accordingly.", MYF(0),
1908+
table->s->db.str, table->s->table_name.str);
1909+
DBUG_RETURN(TRUE);
1910+
}
1911+
19021912
/*
19031913
Pre-acquire audit plugins for events that may potentially occur
19041914
during [UN]INSTALL PLUGIN.

sql/table.cc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -3013,7 +3013,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
30133013

30143014
/* Whether the table definition has already been validated. */
30153015
if (table->s->table_field_def_cache == table_def)
3016-
DBUG_RETURN(FALSE);
3016+
goto end;
30173017

30183018
if (table->s->fields != table_def->count)
30193019
{
@@ -3129,6 +3129,18 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
31293129
if (! error)
31303130
table->s->table_field_def_cache= table_def;
31313131

3132+
end:
3133+
3134+
if (has_keys && !error && !table->key_info)
3135+
{
3136+
my_printf_error(ER_UNKNOWN_ERROR,
3137+
"The table '%s.%s' does not have the necessary key(s) "
3138+
"defined on it. Please check the table definition and "
3139+
"create index(s) accordingly.", MYF(0),
3140+
table->s->db.str, table->s->table_name.str);
3141+
error= TRUE;
3142+
}
3143+
31323144
DBUG_RETURN(error);
31333145
}
31343146

sql/table.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef TABLE_INCLUDED
22
#define TABLE_INCLUDED
33

4-
/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2017, 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
@@ -484,10 +484,11 @@ typedef struct st_ha_data_partition
484484
class Table_check_intact
485485
{
486486
protected:
487+
bool has_keys;
487488
virtual void report_error(uint code, const char *fmt, ...)= 0;
488489

489490
public:
490-
Table_check_intact() {}
491+
Table_check_intact() : has_keys(FALSE) {}
491492
virtual ~Table_check_intact() {}
492493

493494
/** Checks whether a table is intact. */

0 commit comments

Comments
 (0)