Skip to content

Commit

Permalink
MDEV-22337 Assertion `Alloced_length >= (str_length + length +...
Browse files Browse the repository at this point in the history
Fix pointer calculations in the Session_tracker::store.
Most of the fix for this bug goes to the 10.5, but this part should be also fixed
earlier.
  • Loading branch information
Alexey Botchkov committed Apr 29, 2020
1 parent dd5c307 commit 4af4284
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion sql/session_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ void Session_tracker::store(THD *thd, String *buf)
}

size_t length= buf->length() - start;
uchar *data= (uchar *)(buf->ptr() + start);
uchar *data;
uint size;

if ((size= net_length_size(length)) != 1)
Expand All @@ -1703,8 +1703,16 @@ void Session_tracker::store(THD *thd, String *buf)
buf->length(start); // it is safer to have 0-length block in case of error
return;
}

/*
The 'buf->reserve()' can change the buf->ptr() so we cannot
calculate the 'data' earlier.
*/
data= (uchar *)(buf->ptr() + start);
memmove(data + (size - 1), data, length);
}
else
data= (uchar *)(buf->ptr() + start);

net_store_length(data - 1, length);
}
Expand Down

0 comments on commit 4af4284

Please sign in to comment.