Skip to content

Commit ea9751a

Browse files
author
Tor Didriksen
committed
Bug#17003702 ADDRESSSANITIZER BUG IN RUN_PLUGIN_AUTH
Do not access the message buffer of a closed connection.
1 parent cedcb09 commit ea9751a

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

sql-common/client.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ void set_mysql_error(MYSQL *mysql, int errcode, const char *sqlstate)
225225
DBUG_VOID_RETURN;
226226
}
227227

228+
/**
229+
Is this NET instance initialized?
230+
@c my_net_init() and net_end()
231+
*/
232+
233+
my_bool my_net_is_inited(NET *net)
234+
{
235+
return net->buff != NULL;
236+
}
237+
228238
/**
229239
Clear possible error state of struct NET
230240
@@ -2994,7 +3004,12 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len,
29943004

29953005
compile_time_assert(CR_OK == -1);
29963006
compile_time_assert(CR_ERROR == 0);
2997-
if (res > CR_OK && mysql->net.read_pos[0] != 254)
3007+
3008+
/*
3009+
The connection may be closed. If so: do not try to read from the buffer.
3010+
*/
3011+
if (res > CR_OK &&
3012+
(!my_net_is_inited(&mysql->net) || mysql->net.read_pos[0] != 254))
29983013
{
29993014
/*
30003015
the plugin returned an error. write it down in mysql,

tests/mysql_client_test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18011,6 +18011,7 @@ static void test_bug43560(void)
1801118011
rc= mysql_stmt_prepare(stmt, insert_str, strlen(insert_str));
1801218012
check_execute(stmt, rc);
1801318013

18014+
memset(&bind, 0, sizeof(bind));
1801418015
bind.buffer_type= MYSQL_TYPE_STRING;
1801518016
bind.buffer_length= BUFSIZE;
1801618017
bind.buffer= buffer;

0 commit comments

Comments
 (0)