mirror of
https://github.com/MariaDB/server.git
synced 2026-04-30 20:25:32 +02:00
Bug #13708485: malformed resultset packet crashes client
Several fixes : * sql-common/client.c Added a validity check of the fields metadata packet sent by the server. Now libmysql will check if the length of the data sent by the server matches what's expected by the protocol before using the data. * client/mysqltest.cc Fixed the error handling code in mysqltest to avoid sending new commands when the reading the result set failed (and there are unread data in the pipe). * sql_common.h + libmysql/libmysql.c + sql-common/client.c unpack_fields() now generates a proper error when it fails. Added a new argument to this function to support the error generation. * sql/protocol.cc Added a debug trigger to cause the server to send a NULL insted of the packet expected by the client for testing purposes.
This commit is contained in:
parent
4358669767
commit
428ff7f8a0
5 changed files with 27 additions and 12 deletions
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
Copyright (c) 2003, 2012, 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
|
||||
|
|
@ -1268,7 +1268,7 @@ static void cli_fetch_lengths(ulong *to, MYSQL_ROW column,
|
|||
***************************************************************************/
|
||||
|
||||
MYSQL_FIELD *
|
||||
unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
|
||||
unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
|
||||
my_bool default_value, uint server_capabilities)
|
||||
{
|
||||
MYSQL_ROWS *row;
|
||||
|
|
@ -1281,6 +1281,7 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
|
|||
if (!result)
|
||||
{
|
||||
free_rows(data); /* Free old data */
|
||||
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields);
|
||||
|
|
@ -1308,6 +1309,14 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields,
|
|||
field->org_name_length= lengths[5];
|
||||
|
||||
/* Unpack fixed length parts */
|
||||
if (lengths[6] != 12)
|
||||
{
|
||||
/* malformed packet. signal an error. */
|
||||
free_rows(data); /* Free old data */
|
||||
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
pos= (uchar*) row->data[6];
|
||||
field->charsetnr= uint2korr(pos);
|
||||
field->length= (uint) uint4korr(pos+2);
|
||||
|
|
@ -2868,7 +2877,7 @@ get_info:
|
|||
|
||||
if (!(fields=cli_read_rows(mysql,(MYSQL_FIELD*)0, protocol_41(mysql) ? 7:5)))
|
||||
DBUG_RETURN(1);
|
||||
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,
|
||||
if (!(mysql->fields=unpack_fields(mysql, fields,&mysql->field_alloc,
|
||||
(uint) field_count,0,
|
||||
mysql->server_capabilities)))
|
||||
DBUG_RETURN(1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue