Skip to content

Commit 4012ca9

Browse files
author
Tatiana Azundris Nuernberg
committed
Bug#20712046: SHOW PROCESSLIST AND PERFORMANCE_SCHEMA TABLES DO NOT MASK PASSWORD FROM QUERY
If a rewritten version of a given query exists (to hide passwords etc.), use that instead of the original query in a) SHOW PROCESSLIST b) information_schema.processlist c) performance_schema.threads in addition to the support for d) performance_schema.events_statements_current e) performance_schema.events_statements_history f) performance_schema.events_statements_history_long v5.6 Approved by: Karthik Kamath <[email protected]>
1 parent ee86e7b commit 4012ca9

File tree

10 files changed

+75
-27
lines changed

10 files changed

+75
-27
lines changed

mysql-test/include/check_ftwrl_incompatible.inc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# $con_aux1 Name of the 1st aux connection to be used by this script.
77
# $con_aux2 Name of the 2nd aux connection to be used by this script.
88
# $statement The statement to be checked.
9+
# $waitfor Wait for this statement in process-list. If empty,
10+
# use $statement. Reset at end of include.
911
# $cleanup_stmt1 The 1st statement to be run in order to revert effects
1012
# of statement to be checked.
1113
# $cleanup_stmt2 The 2nd statement to be run in order to revert effects
@@ -66,14 +68,26 @@ connection $con_aux1;
6668

6769
--enable_result_log
6870
--enable_query_log
71+
if (!$waitfor)
72+
{
73+
let $wait_condition=
74+
select count(*) = 1 from information_schema.processlist
75+
where (state = "Waiting for global read lock" or
76+
state = "Waiting for commit lock") and
77+
info = "$statement";
78+
}
79+
if ($waitfor)
80+
{
6981
let $wait_condition=
7082
select count(*) = 1 from information_schema.processlist
7183
where (state = "Waiting for global read lock" or
7284
state = "Waiting for commit lock") and
73-
info = "$statement";
85+
info = "$waitfor";
86+
}
7487
--source include/wait_condition.inc
7588
--disable_result_log
7689
--disable_query_log
90+
let $waitfor=;
7791

7892
if ($success)
7993
{

mysql-test/suite/perfschema/r/stage_mdl_procedure.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test.f1()
1515
drop procedure test.p1;
1616
call dump_one_thread('user1');
1717
username event_name sql_text
18-
user1 statement/sql/select select test.f1()
18+
user1 statement/sql/select call test.p1()
1919
username event_name nesting_event_type
2020
username event_name nesting_event_type
2121
user1 stage/sql/executing STATEMENT

mysql-test/t/flush_read_lock.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ let $skip_3rd_check= ;
14961496
--echo # 31.d.I) SET PASSWORD is incompatible with FTWRL as it changes data.
14971497
create user mysqltest_u1;
14981498
let $statement= set password for 'mysqltest_u1' = password('');
1499+
let $waitfor= SET PASSWORD FOR `mysqltest_u1`@`%`=<secret>;
14991500
let $cleanup_stmt1= ;
15001501
--echo # Skip last part of compatibility testing as our helper debug
15011502
--echo # sync-point doesn't work for SET statements.

sql/log_event.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4802,6 +4802,7 @@ int Query_log_event::do_apply_event(Relay_log_info const *rli,
48024802
to fix this if any refactoring happens here sometime.
48034803
*/
48044804
thd->set_query((char*) query_arg, q_len_arg, thd->charset());
4805+
thd->reset_query_for_display();
48054806
}
48064807
}
48074808
if (time_zone_len)
@@ -13693,6 +13694,7 @@ int Rows_query_log_event::do_apply_event(Relay_log_info const *rli)
1369313694
DBUG_ASSERT(rli->info_thd == thd);
1369413695
/* Set query for writing Rows_query log event into binlog later.*/
1369513696
thd->set_query(m_rows_query, (uint32) strlen(m_rows_query));
13697+
thd->set_query_for_display(m_rows_query, strlen(m_rows_query));
1369613698

1369713699
DBUG_ASSERT(rli->rows_query_ev == NULL);
1369813700

sql/sp_instr.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2012, 2019, 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
@@ -829,6 +829,8 @@ bool sp_instr_stmt::execute(THD *thd, uint *nextp)
829829

830830
DBUG_PRINT("info", ("query: '%.*s'", (int) m_query.length, m_query.str));
831831

832+
thd->set_query_for_display(m_query.str, m_query.length);
833+
832834
const CSET_STRING query_backup= thd->query_string;
833835

834836
#if defined(ENABLED_PROFILING)

sql/sql_class.cc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2019, 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
@@ -4674,10 +4674,6 @@ void THD::set_query(const CSET_STRING &string_arg)
46744674
mysql_mutex_lock(&LOCK_thd_data);
46754675
set_query_inner(string_arg);
46764676
mysql_mutex_unlock(&LOCK_thd_data);
4677-
4678-
#ifdef HAVE_PSI_THREAD_INTERFACE
4679-
PSI_THREAD_CALL(set_thread_info)(query(), query_length());
4680-
#endif
46814677
}
46824678

46834679
/** Assign a new value to thd->query and thd->query_id. */

sql/sql_class.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights
1+
/* Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights
22
reserved.
33
44
This program is free software; you can redistribute it and/or modify
@@ -4028,6 +4028,13 @@ class THD :public MDL_context_owner,
40284028
Assign a new value to thd->query and thd->query_id and mysys_var.
40294029
Protected with LOCK_thd_data mutex.
40304030
*/
4031+
void set_query_for_display(const char *query_arg, size_t query_length_arg) {
4032+
MYSQL_SET_STATEMENT_TEXT(m_statement_psi, query_arg, query_length_arg);
4033+
#ifdef HAVE_PSI_THREAD_INTERFACE
4034+
PSI_THREAD_CALL(set_thread_info)(query_arg, query_length_arg);
4035+
#endif
4036+
}
4037+
void reset_query_for_display(void) { set_query_for_display(NULL, 0); }
40314038
void set_query(char *query_arg, uint32 query_length_arg,
40324039
const CHARSET_INFO *cs_arg)
40334040
{
@@ -4038,8 +4045,9 @@ class THD :public MDL_context_owner,
40384045
set_query(CSET_STRING(query_arg, query_length_arg, charset()));
40394046
}
40404047
void set_query(const CSET_STRING &str); /* Mutex protected */
4041-
void reset_query() /* Mutex protected */
4042-
{ set_query(CSET_STRING()); }
4048+
void reset_query() { /* Mutex protected */
4049+
set_query(CSET_STRING());
4050+
rewritten_query.free(); }
40434051
void set_query_and_id(char *query_arg, uint32 query_length_arg,
40444052
const CHARSET_INFO *cs, query_id_t new_query_id);
40454053
void set_query_id(query_id_t new_query_id);

sql/sql_parse.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2019, 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
@@ -3186,8 +3186,10 @@ case SQLCOM_PREPARE:
31863186
case SQLCOM_SLAVE_START:
31873187
{
31883188
mysql_mutex_lock(&LOCK_active_mi);
3189-
if (active_mi != NULL)
3189+
if (active_mi != NULL) {
3190+
DEBUG_SYNC(thd, "begin_start_slave");
31903191
res= start_slave(thd, active_mi, 1 /* net report*/);
3192+
}
31913193
else
31923194
my_message(ER_SLAVE_CONFIGURATION, ER(ER_SLAVE_CONFIGURATION),
31933195
MYF(0));
@@ -5046,6 +5048,7 @@ case SQLCOM_PREPARE:
50465048
{
50475049
thd->killed= THD::NOT_KILLED;
50485050
thd->mysys_var->abort= 0;
5051+
thd->reset_query_for_display();
50495052
}
50505053
if (thd->is_error() || (thd->variables.option_bits & OPTION_MASTER_SQL_ERROR))
50515054
trans_rollback_stmt(thd);
@@ -6346,15 +6349,18 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
63466349
{
63476350
lex->safe_to_cache_query= false; // see comments below
63486351

6349-
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi,
6350-
thd->rewritten_query.c_ptr_safe(),
6351-
thd->rewritten_query.length());
6352-
}
6353-
else
6354-
{
6352+
thd->set_query_for_display(thd->rewritten_query.c_ptr_safe(),
6353+
thd->rewritten_query.length());
6354+
} else if (thd->slave_thread) {
6355+
/*
6356+
In the slave, we add the information to pfs.events_statements_history,
6357+
but not to pfs.threads, as that is what the test suite expects.
6358+
*/
63556359
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi,
63566360
thd->query(),
63576361
thd->query_length());
6362+
} else {
6363+
thd->set_query_for_display(thd->query(), thd->query_length());
63586364
}
63596365

63606366
if (!(opt_log_raw || thd->slave_thread))
@@ -6472,9 +6478,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
64726478
SQL injection, finding the source of the SQL injection is critical, so the
64736479
design choice is to log the query text of broken queries (a).
64746480
*/
6475-
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi,
6476-
thd->query(),
6477-
thd->query_length());
6481+
thd->set_query_for_display(thd->query(), thd->query_length());
64786482

64796483
/* Instrument this broken statement as "statement/sql/error" */
64806484
thd->m_statement_psi= MYSQL_REFINE_STATEMENT(thd->m_statement_psi,
@@ -6513,6 +6517,8 @@ void mysql_parse(THD *thd, char *rawbuf, uint length,
65136517
parser_state->m_lip.found_semicolon= NULL;
65146518
}
65156519

6520+
DEBUG_SYNC(thd, "query_rewritten");
6521+
65166522
DBUG_VOID_RETURN;
65176523
}
65186524

sql/sql_show.cc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,8 +2168,17 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose)
21682168
/* Lock THD mutex that protects its data when looking at it. */
21692169
if (tmp->query())
21702170
{
2171-
uint length= min<uint>(max_query_length, tmp->query_length());
2172-
char *q= thd->strmake(tmp->query(),length);
2171+
const char *query_str;
2172+
size_t query_length;
2173+
if ((query_length = tmp->rewritten_query.length()) > 0) {
2174+
query_str = tmp->rewritten_query.c_ptr();
2175+
} else {
2176+
query_length = tmp->query_length();
2177+
query_str = tmp->query();
2178+
}
2179+
2180+
uint length= min<uint>(max_query_length, query_length);
2181+
char *q= thd->strmake(query_str, length);
21732182
/* Safety: in case strmake failed, we set length to 0. */
21742183
thd_info->query_string=
21752184
CSET_STRING(q, q ? length : 0, tmp->query_charset());
@@ -2309,9 +2318,18 @@ int fill_schema_processlist(THD* thd, TABLE_LIST* tables, Item* cond)
23092318
/* INFO */
23102319
if (tmp->query())
23112320
{
2321+
const char *query_str;
2322+
size_t query_length;
2323+
2324+
if ((query_length = tmp->rewritten_query.length()) > 0) {
2325+
query_str = tmp->rewritten_query.c_ptr();
2326+
} else {
2327+
query_length = tmp->query_length();
2328+
query_str = tmp->query();
2329+
}
23122330
size_t const width=
2313-
min<size_t>(PROCESS_LIST_INFO_WIDTH, tmp->query_length());
2314-
table->field[7]->store(tmp->query(), width, cs);
2331+
min<size_t>(PROCESS_LIST_INFO_WIDTH, query_length);
2332+
table->field[7]->store(query_str, width, cs);
23152333
table->field[7]->set_notnull();
23162334
}
23172335
mysql_mutex_unlock(&tmp->LOCK_thd_data);

sql/sql_yacc.yy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2000, 2019, 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
@@ -14842,6 +14842,7 @@ option_value_no_option_type:
1484214842
lex->autocommit= TRUE;
1484314843
lex->is_set_password_sql= true;
1484414844
lex->is_change_password= TRUE;
14845+
lex->contains_plaintext_password= true;
1484514846

1484614847
if (sp)
1484714848
sp->m_flags|= sp_head::HAS_SET_AUTOCOMMIT_STMT;

0 commit comments

Comments
 (0)