Skip to content

Commit cc6a028

Browse files
committed
BUG#20479565: STD::STRING GTID_SET::ENCODE() IS NOT SAFE ON WINDOWS
Method encode() of Gtid_set class was returning a local variable of type std::string, although this was working OK on all Posix platforms, on Windows memory was being corrupted what was causing method to fail. To fix the above issue, method std::string Gtid_set::encode() was removed.
1 parent cd30716 commit cc6a028

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

plugin/replication_observers_example/replication_observers_example.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,10 +512,15 @@ int validate_plugin_server_requirements(Trans_param *param)
512512
if (tcle->is_valid())
513513
{
514514
Gtid_set *snapshot_version= tcle->get_snapshot_version();
515+
size_t snapshot_version_len= snapshot_version->get_encoded_length();
516+
uchar* snapshot_version_buf= (uchar *)my_malloc(PSI_NOT_INSTRUMENTED,
517+
snapshot_version_len, MYF(0));
518+
snapshot_version->encode(snapshot_version_buf);
515519
my_plugin_log_message(&plugin_info_ptr,
516520
MY_INFORMATION_LEVEL,
517521
"snapshot version is '%s'",
518-
snapshot_version->encode().c_str());
522+
snapshot_version_buf);
523+
my_free(snapshot_version_buf);
519524
success++;
520525
}
521526
else

sql/rpl_gtid.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,10 +1676,6 @@ class Gtid_set
16761676
Encodes this Gtid_set as a binary string.
16771677
*/
16781678
void encode(uchar *buf) const;
1679-
/**
1680-
Encodes this Gtid_set as a binary string using std::string.
1681-
*/
1682-
std::string encode() const;
16831679
/**
16841680
Returns the length of this Gtid_set when encoded using the
16851681
encode() function.

sql/rpl_gtid_set.cc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,21 +1441,6 @@ void Gtid_set::encode(uchar *buf) const
14411441
}
14421442

14431443

1444-
std::string Gtid_set::encode() const
1445-
{
1446-
DBUG_ENTER("std::string Gtid_set::encode()");
1447-
1448-
size_t len= get_encoded_length();
1449-
uchar* buf= (uchar *)my_malloc(key_memory_Gtid_set_to_string,
1450-
len, MYF(MY_WME));
1451-
encode(buf);
1452-
std::string result(reinterpret_cast<const char*>(buf), len);
1453-
my_free(buf);
1454-
1455-
DBUG_RETURN(result);
1456-
}
1457-
1458-
14591444
enum_return_status Gtid_set::add_gtid_encoding(const uchar *encoded,
14601445
size_t length,
14611446
size_t *actual_length)

0 commit comments

Comments
 (0)