diff options
author | Magne Mahre <magne.mahre@oracle.com> | 2011-10-07 14:08:31 +0200 |
---|---|---|
committer | Magne Mahre <magne.mahre@oracle.com> | 2011-10-07 14:08:31 +0200 |
commit | e02c3d7fb7e59bcede73392ab0da5a5228859e0f (patch) | |
tree | 6b78785fe9d18efb7a0fff1422ca1168662e0834 /sql/sp_head.cc | |
parent | 41dc3049281c1718e49d80eaf0cf068def9519b5 (diff) | |
download | mariadb-git-e02c3d7fb7e59bcede73392ab0da5a5228859e0f.tar.gz |
BUG#12589870 CRASHES WITH MULTIQUERY PACKET + USE<DB> + QUERY CACHE
A buffer large enough to hold the query _plus_ some additional
data is allocated before parsing is started. The additional data
is used by the query cache, and consists of the name of the current
database and a set of flags.
When a packet containing multiple SQL statements is sent to the
server and one of the statements changes the current database
(a "USE <db>" statement), and the name of the new current database
is longer than of the previous, there is not enough space in the
buffer for the new name, and we write out over the buffer boundary.
The fix adds an extra field to store the number of bytes
allocated to the database name in the buffer. If the current
database name changes, and the new name is longer than the
previous one, we refuse to cache the query.
Diffstat (limited to 'sql/sp_head.cc')
-rw-r--r-- | sql/sp_head.cc | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 95a7eda0540..70ffb0a36ab 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1029,12 +1029,22 @@ subst_spvars(THD *thd, sp_instr *instr, LEX_STRING *query_str) /* Allocate additional space at the end of the new query string for the query_cache_send_result_to_client function. + + The query buffer layout is: + buffer :== + <statement> The input statement(s) + '\0' Terminating null char + <length> Length of following current database name (size_t) + <db_name> Name of current database + <flags> Flags struct */ - buf_len= qbuf.length() + thd->db_length + 1 + QUERY_CACHE_FLAGS_SIZE + 1; + buf_len= qbuf.length() + 1 + sizeof(size_t) + thd->db_length + + QUERY_CACHE_FLAGS_SIZE + 1; if ((pbuf= (char *) alloc_root(thd->mem_root, buf_len))) { memcpy(pbuf, qbuf.ptr(), qbuf.length()); pbuf[qbuf.length()]= 0; + *(size_t *)(pbuf+qbuf.length()+1)= thd->db_length; } else DBUG_RETURN(TRUE); |