Commit 7b86fda0 authored by Oleksandr Byelkin's avatar Oleksandr Byelkin

Fixed length of codding of COM_MULTI parts.

parent 6dfa1d37
...@@ -1476,13 +1476,16 @@ uint maria_multi_check(THD *thd, char *packet, uint packet_length) ...@@ -1476,13 +1476,16 @@ uint maria_multi_check(THD *thd, char *packet, uint packet_length)
DBUG_ENTER("maria_multi_check"); DBUG_ENTER("maria_multi_check");
while (packet_length) while (packet_length)
{ {
char *packet_start= packet;
size_t subpacket_length= net_field_length((uchar **)&packet_start);
uint length_length= packet_start - packet;
// length of command + 3 bytes where that length was stored // length of command + 3 bytes where that length was stored
uint subpacket_length= (uint3korr(packet) + 3); DBUG_PRINT("info", ("sub-packet length: %ld + %d command: %x",
DBUG_PRINT("info", ("sub-packet length: %d command: %x", (ulong)subpacket_length, length_length,
subpacket_length, packet[3])); packet_start[3]));
if (subpacket_length == 3 || if (subpacket_length == 0 ||
subpacket_length > packet_length) (subpacket_length + length_length) > packet_length)
{ {
my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR), my_message(ER_UNKNOWN_COM_ERROR, ER_THD(thd, ER_UNKNOWN_COM_ERROR),
MYF(0)); MYF(0));
...@@ -1490,8 +1493,8 @@ uint maria_multi_check(THD *thd, char *packet, uint packet_length) ...@@ -1490,8 +1493,8 @@ uint maria_multi_check(THD *thd, char *packet, uint packet_length)
} }
counter++; counter++;
packet+= subpacket_length; packet= packet_start + subpacket_length;
packet_length-= subpacket_length; packet_length-= (subpacket_length + length_length);
} }
DBUG_RETURN(counter); DBUG_RETURN(counter);
} }
...@@ -2231,8 +2234,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -2231,8 +2234,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break; break;
{ {
char *packet_start= packet;
/* We have to store next length because it will be destroyed by '\0' */ /* We have to store next length because it will be destroyed by '\0' */
uint next_subpacket_length= uint3korr(packet); size_t next_subpacket_length= net_field_length((uchar **)&packet_start);
uint next_length_length= packet_start - packet;
unsigned char *readbuff= net->buff; unsigned char *readbuff= net->buff;
if (net_allocate_new_packet(net, thd, MYF(0))) if (net_allocate_new_packet(net, thd, MYF(0)))
...@@ -2246,13 +2251,19 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -2246,13 +2251,19 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
while (packet_length) while (packet_length)
{ {
current_com++; current_com++;
uint subpacket_length= next_subpacket_length + 3; size_t subpacket_length= next_subpacket_length + next_length_length;
uint length_length= next_length_length;
if (subpacket_length < packet_length) if (subpacket_length < packet_length)
next_subpacket_length= uint3korr(packet + subpacket_length); {
packet_start= packet + subpacket_length;
next_subpacket_length= net_field_length((uchar**)&packet_start);
next_length_length= packet_start - (packet + subpacket_length);
}
/* safety like in do_command() */ /* safety like in do_command() */
packet[subpacket_length]= '\0'; packet[subpacket_length]= '\0';
enum enum_server_command subcommand= fetch_command(thd, (packet + 3)); enum enum_server_command subcommand=
fetch_command(thd, (packet + length_length));
if (server_command_flags[subcommand] & CF_NO_COM_MULTI) if (server_command_flags[subcommand] & CF_NO_COM_MULTI)
{ {
...@@ -2260,8 +2271,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -2260,8 +2271,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
goto com_multi_end; goto com_multi_end;
} }
if (dispatch_command(subcommand, thd, packet + (1 + 3), if (dispatch_command(subcommand, thd, packet + (1 + length_length),
subpacket_length - (1 + 3), TRUE, subpacket_length - (1 + length_length), TRUE,
(current_com != counter))) (current_com != counter)))
{ {
DBUG_ASSERT(thd->is_error()); DBUG_ASSERT(thd->is_error());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment