Skip to content

Commit 96de6c4

Browse files
Fix reset of THD query when trx metadata is enabled
Summary: When a Rows_query_log_event contains trx metadata the real query is present just after the metadata comment. Due to this the THD is assigned the query after going past the metadata in Rows_query_log_event::do_apply_event() but the destructor was resetting the query by comparing the THD query to the beginning of the rows query. This was causing a read-after-free error. Reviewed By: yashtc Differential Revision: D7899271 fbshipit-source-id: 8374804
1 parent fc7bcca commit 96de6c4

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sql/log_event.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14883,7 +14883,7 @@ Rows_query_log_event::Rows_query_log_event(const char *buf, uint event_len,
1488314883
int offset= common_header_len + post_header_len + 1;
1488414884
int len= event_len - offset;
1488514885
if (!(m_rows_query= (char*) my_malloc(len+1, MYF(MY_WME))))
14886-
return;
14886+
DBUG_VOID_RETURN;
1488714887
strmake(m_rows_query, buf + offset, len);
1488814888
DBUG_PRINT("info", ("m_rows_query: %s", m_rows_query));
1488914889
DBUG_VOID_RETURN;
@@ -14896,7 +14896,14 @@ Rows_query_log_event::~Rows_query_log_event()
1489614896
// the m_rows_query.
1489714897
if (thd) {
1489814898
mysql_mutex_lock(&thd->LOCK_thd_data);
14899-
if (thd->query() == m_rows_query)
14899+
auto query= m_rows_query;
14900+
if (has_trx_meta_data())
14901+
{
14902+
// move past the trx metadata
14903+
DBUG_ASSERT(strstr(m_rows_query, "*/") != NULL);
14904+
query= strstr(m_rows_query, "*/") + 2;
14905+
}
14906+
if (thd->query() == query)
1490014907
thd->set_query(CSET_STRING(), false);
1490114908
mysql_mutex_unlock(&thd->LOCK_thd_data);
1490214909
}

0 commit comments

Comments
 (0)