Skip to content

Commit

Permalink
BUG#26881798: SERVER EXITS WHEN PRIMARY KEY IN MYSQL.PROC
Browse files Browse the repository at this point in the history
              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.
  • Loading branch information
karthik-kamath committed Dec 5, 2017
1 parent ecc5a07 commit 9e1035c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
4 changes: 3 additions & 1 deletion sql/event_db_repository.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -174,6 +174,8 @@ class Event_db_intact : public Table_check_intact
error_log_print(ERROR_LEVEL, fmt, args);
va_end(args);
}
public:
Event_db_intact() { has_keys= TRUE; }
};

/** In case of an error, a message is printed to the error log. */
Expand Down
4 changes: 2 additions & 2 deletions sql/sp.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -351,7 +351,7 @@ class Proc_table_intact : public Table_check_intact
bool m_print_once;

public:
Proc_table_intact() : m_print_once(TRUE) {}
Proc_table_intact() : m_print_once(TRUE) { has_keys= TRUE; }

protected:
void report_error(uint code, const char *fmt, ...);
Expand Down
4 changes: 3 additions & 1 deletion sql/sql_acl.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -949,6 +949,8 @@ class Acl_table_intact : public Table_check_intact
va_end(args);
}
}
public:
Acl_table_intact() { has_keys= TRUE; }
};

#define IP_ADDR_STRLEN (3 + 1 + 3 + 1 + 3 + 1 + 3)
Expand Down
12 changes: 11 additions & 1 deletion sql/sql_plugin.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -1899,6 +1899,16 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name)
if (! (table= open_ltable(thd, &tables, TL_WRITE, MYSQL_LOCK_IGNORE_TIMEOUT)))
DBUG_RETURN(TRUE);

if (!table->key_info)
{
my_printf_error(ER_UNKNOWN_ERROR,
"The table '%s.%s' does not have the necessary key(s) "
"defined on it. Please check the table definition and "
"create index(s) accordingly.", MYF(0),
table->s->db.str, table->s->table_name.str);
DBUG_RETURN(TRUE);
}

/*
Pre-acquire audit plugins for events that may potentially occur
during [UN]INSTALL PLUGIN.
Expand Down
16 changes: 14 additions & 2 deletions sql/table.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -3013,7 +3013,7 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)

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

if (table->s->fields != table_def->count)
{
Expand Down Expand Up @@ -3129,6 +3129,18 @@ Table_check_intact::check(TABLE *table, const TABLE_FIELD_DEF *table_def)
if (! error)
table->s->table_field_def_cache= table_def;

end:

if (has_keys && !error && !table->key_info)
{
my_printf_error(ER_UNKNOWN_ERROR,
"The table '%s.%s' does not have the necessary key(s) "
"defined on it. Please check the table definition and "
"create index(s) accordingly.", MYF(0),
table->s->db.str, table->s->table_name.str);
error= TRUE;
}

DBUG_RETURN(error);
}

Expand Down
5 changes: 3 additions & 2 deletions sql/table.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef TABLE_INCLUDED
#define TABLE_INCLUDED

/* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -484,10 +484,11 @@ typedef struct st_ha_data_partition
class Table_check_intact
{
protected:
bool has_keys;
virtual void report_error(uint code, const char *fmt, ...)= 0;

public:
Table_check_intact() {}
Table_check_intact() : has_keys(FALSE) {}
virtual ~Table_check_intact() {}

/** Checks whether a table is intact. */
Expand Down

0 comments on commit 9e1035c

Please sign in to comment.