mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
Fix for BUG#7716: in in_string::set() take into account that the value returned
by item->val_str() may be a substring of the passed string. Disallow string=its_substring assignment in String::operator=(). mysql-test/r/func_misc.result: Testcase for BUG#7716 mysql-test/t/func_misc.test: Testcase for BUG#7716 sql/item_cmpfunc.cc: Fix for BUG#7716: in in_string::set() take into account that the string returned by item->val_str(S) may be not S but use the buffer owned by S. sql/sql_string.h: * Added assert: String& String::operator=(const String&) may not be used to do assignments like str = string_that_uses_buffer_owned_by_str * Added String::uses_buffer_owned_by().
This commit is contained in:
@ -182,6 +182,11 @@ public:
|
||||
{
|
||||
if (&s != this)
|
||||
{
|
||||
/*
|
||||
It is forbidden to do assignments like
|
||||
some_string = substring_of_that_string
|
||||
*/
|
||||
DBUG_ASSERT(!s.uses_buffer_owned_by(this));
|
||||
free();
|
||||
Ptr=s.Ptr ; str_length=s.str_length ; Alloced_length=s.Alloced_length;
|
||||
alloced=0;
|
||||
@ -313,4 +318,9 @@ public:
|
||||
|
||||
/* Swap two string objects. Efficient way to exchange data without memcpy. */
|
||||
void swap(String &s);
|
||||
|
||||
inline bool uses_buffer_owned_by(const String *s) const
|
||||
{
|
||||
return (s->alloced && Ptr >= s->Ptr && Ptr < s->Ptr + s->str_length);
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user