Skip to content

Commit a63a250

Browse files
author
Neha Kumari
committed
BUG#23509275 :DBUG_PRINT in THD::decide_logging_format prints incorrectly, access out-of-bound
Problem: In debug builds, there is a chance that an out-of-bounds read is performed when tables are locked in LTM_PRELOCKED_UNDER_LOCK_TABLES mode. It can happen because the debug code uses enum values as index for an array of mode descriptions, but it only takes into consideration 3 out of 4 of the enum values. Fix: This patch fixes it by implementing a getter for the enum which returns a string representation of the enum, effectively removing the out-of-bounds read. Moreover, it also fixes the lock mode descriptions that would be print out in debug builds.
1 parent 2674cf9 commit a63a250

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

sql/sql_class.cc

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2016, 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
@@ -4246,6 +4246,25 @@ has_write_table_auto_increment_not_first_in_pk(TABLE_LIST *tables)
42464246
return 0;
42474247
}
42484248

4249+
#ifndef DBUG_OFF
4250+
const char * get_locked_tables_mode_name(enum_locked_tables_mode locked_tables_mode)
4251+
{
4252+
switch (locked_tables_mode)
4253+
{
4254+
case LTM_NONE:
4255+
return "LTM_NONE";
4256+
case LTM_LOCK_TABLES:
4257+
return "LTM_LOCK_TABLES";
4258+
case LTM_PRELOCKED:
4259+
return "LTM_PRELOCKED";
4260+
case LTM_PRELOCKED_UNDER_LOCK_TABLES:
4261+
return "LTM_PRELOCKED_UNDER_LOCK_TABLES";
4262+
default:
4263+
return "Unknown table lock mode";
4264+
}
4265+
}
4266+
#endif
4267+
42494268
/**
42504269
Decide on logging format to use for the statement and issue errors
42514270
or warnings as needed. The decision depends on the following
@@ -4397,15 +4416,8 @@ int THD::decide_logging_format(TABLE_LIST *tables)
43974416
TABLE* prev_access_table= NULL;
43984417

43994418
#ifndef DBUG_OFF
4400-
{
4401-
static const char *prelocked_mode_name[] = {
4402-
"NON_PRELOCKED",
4403-
"PRELOCKED",
4404-
"PRELOCKED_UNDER_LOCK_TABLES",
4405-
};
4406-
DBUG_PRINT("debug", ("prelocked_mode: %s",
4407-
prelocked_mode_name[locked_tables_mode]));
4408-
}
4419+
DBUG_PRINT("debug", ("prelocked_mode: %s",
4420+
get_locked_tables_mode_name(locked_tables_mode)));
44094421
#endif
44104422

44114423
if (variables.binlog_format != BINLOG_FORMAT_ROW && tables)

sql/sql_class.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,8 @@ typedef I_List<Item_change_record> Item_change_list;
963963
/**
964964
Type of locked tables mode.
965965
See comment for THD::locked_tables_mode for complete description.
966+
While adding new enum values add them to the getter method for this enum
967+
declared below and defined in sql_class.cc as well.
966968
*/
967969

968970
enum enum_locked_tables_mode
@@ -973,6 +975,15 @@ enum enum_locked_tables_mode
973975
LTM_PRELOCKED_UNDER_LOCK_TABLES
974976
};
975977

978+
#ifndef DBUG_OFF
979+
/**
980+
Getter for the enum enum_locked_tables_mode
981+
@param locked_tables_mode enum for types of locked tables mode
982+
983+
@return The string represantation of that enum value
984+
*/
985+
const char * get_locked_tables_mode_name(enum_locked_tables_mode locked_tables_mode);
986+
#endif
976987

977988
/**
978989
Class that holds information about tables which were opened and locked

0 commit comments

Comments
 (0)