diff options
author | Alexander Barkov <bar@mariadb.com> | 2021-10-27 10:50:15 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2021-10-27 10:50:15 +0400 |
commit | 2ed148c8d7b0133ecd17377587facadc7e76e9e8 (patch) | |
tree | ba0d743fa1d29bef3cb32c6ebfcf4f165f43da91 /storage | |
parent | 4b8340d89990a8105561888059ec6e3543bed41d (diff) | |
download | mariadb-git-2ed148c8d7b0133ecd17377587facadc7e76e9e8.tar.gz |
MDEV-25402 Assertion `!str || str != Ptr' failed in String::copy
The assert inside String::copy() prevents copying from from "str"
if its own String::Ptr also points to the same memory.
The idea of the assert is that copy() performs memory reallocation,
and this reallocation can free (and thus invalidate) the memory pointed by Ptr,
which can lead to further copying from a freed memory.
The assert was incomplete: copy() can free the memory pointed by its Ptr
only if String::alloced is true!
If the String is not alloced, it is still safe to copy even from
the location pointed by Ptr.
This scenario demonstrates a safe copy():
const char *tmp= "123";
String str1(tmp, 3);
String str2(tmp, 3);
// This statement is safe:
str2.copy(str1->ptr(), str1->length(), str1->charset(), cs_to, &errors);
Inside the copy() the parameter "str" is equal to String::Ptr in this example.
But it's still ok to reallocate the memory for str2, because str2
was a constant before the copy() call. Thus reallocation does not
make the memory pointed by str1->ptr() invalid.
Adjusting the assert condition to allow copying for constant strings.
Diffstat (limited to 'storage')
0 files changed, 0 insertions, 0 deletions