summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
authorJoerg Bruehe <joerg@mysql.com>2008-11-10 20:32:45 +0100
committerJoerg Bruehe <joerg@mysql.com>2008-11-10 20:32:45 +0100
commita1e2d2d14615b0ccac6b1246a58cd347effaeefb (patch)
tree0c6bedc8298d6ba68c23420c95626e2b52466499 /sql/sql_class.cc
parent12ad7f3b9da5e0563c24698856102b4b646cea82 (diff)
parent9a0637750a4775e199b3915bd83e630540729d64 (diff)
downloadmariadb-git-a1e2d2d14615b0ccac6b1246a58cd347effaeefb.tar.gz
Merge main 5.1 -> 5.1-build
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc39
1 files changed, 27 insertions, 12 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 12b773c91d0..e9c888136cb 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -306,20 +306,25 @@ void thd_inc_row_count(THD *thd)
thd->row_count++;
}
-/*
+
+/**
Dumps a text description of a thread, its security context
(user, host) and the current query.
- SYNOPSIS
- thd_security_context()
- thd current thread context
- buffer pointer to preferred result buffer
- length length of buffer
- max_query_len how many chars of query to copy (0 for all)
-
- RETURN VALUES
- pointer to string
+ @param thd current thread context
+ @param buffer pointer to preferred result buffer
+ @param length length of buffer
+ @param max_query_len how many chars of query to copy (0 for all)
+
+ @req LOCK_thread_count
+
+ @note LOCK_thread_count mutex is not necessary when the function is invoked on
+ the currently running thread (current_thd) or if the caller in some other
+ way guarantees that access to thd->query is serialized.
+
+ @return Pointer to string
*/
+
extern "C"
char *thd_security_context(THD *thd, char *buffer, unsigned int length,
unsigned int max_query_len)
@@ -328,6 +333,16 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
const Security_context *sctx= &thd->main_security_ctx;
char header[64];
int len;
+ /*
+ The pointers thd->query and thd->proc_info might change since they are
+ being modified concurrently. This is acceptable for proc_info since its
+ values doesn't have to very accurate and the memory it points to is static,
+ but we need to attempt a snapshot on the pointer values to avoid using NULL
+ values. The pointer to thd->query however, doesn't point to static memory
+ and has to be protected by LOCK_thread_count or risk pointing to
+ uninitialized memory.
+ */
+ const char *proc_info= thd->proc_info;
len= my_snprintf(header, sizeof(header),
"MySQL thread id %lu, query id %lu",
@@ -353,10 +368,10 @@ char *thd_security_context(THD *thd, char *buffer, unsigned int length,
str.append(sctx->user);
}
- if (thd->proc_info)
+ if (proc_info)
{
str.append(' ');
- str.append(thd->proc_info);
+ str.append(proc_info);
}
if (thd->query)