summaryrefslogtreecommitdiff
path: root/storage
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@mysql.com>2010-03-08 00:33:07 +0100
committerVladislav Vaintroub <vvaintroub@mysql.com>2010-03-08 00:33:07 +0100
commit057c2b35c3a0e441ba4d849ec0cf8e0f62f75de8 (patch)
treef70ad4a9cbf73be2fb0ba47a007bce0d966a63a5 /storage
parent402cab754af51997f575bb98d647e5f4fd182f10 (diff)
parenta7c9bf2ccf1ed7734e21adbf21b4ec93ec86aaa8 (diff)
downloadmariadb-git-057c2b35c3a0e441ba4d849ec0cf8e0f62f75de8.tar.gz
merge
Diffstat (limited to 'storage')
-rw-r--r--storage/perfschema/pfs_instr.cc22
-rw-r--r--storage/perfschema/unittest/pfs-t.cc15
2 files changed, 34 insertions, 3 deletions
diff --git a/storage/perfschema/pfs_instr.cc b/storage/perfschema/pfs_instr.cc
index 28b54cc6979..fbaac621dfb 100644
--- a/storage/perfschema/pfs_instr.cc
+++ b/storage/perfschema/pfs_instr.cc
@@ -746,6 +746,26 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
}
}
+ char safe_buffer[FN_REFLEN];
+ const char *safe_filename;
+
+ if (len >= FN_REFLEN)
+ {
+ /*
+ The instrumented code uses file names that exceeds FN_REFLEN.
+ This could be legal for instrumentation on non mysys APIs,
+ so we support it.
+ Truncate the file name so that:
+ - it fits into pfs->m_filename
+ - it is safe to use mysys apis to normalize the file name.
+ */
+ memcpy(safe_buffer, filename, FN_REFLEN - 2);
+ safe_buffer[FN_REFLEN - 1]= 0;
+ safe_filename= safe_buffer;
+ }
+ else
+ safe_filename= filename;
+
/*
Normalize the file name to avoid duplicates when using aliases:
- absolute or relative paths
@@ -759,7 +779,7 @@ find_or_create_file(PFS_thread *thread, PFS_file_class *klass,
Ignore errors, the file may not exist.
my_realpath always provide a best effort result in buffer.
*/
- (void) my_realpath(buffer, filename, MYF(0));
+ (void) my_realpath(buffer, safe_filename, MYF(0));
normalized_filename= buffer;
normalized_length= strlen(normalized_filename);
diff --git a/storage/perfschema/unittest/pfs-t.cc b/storage/perfschema/unittest/pfs-t.cc
index fcbaf4aeb8f..2b64aec3416 100644
--- a/storage/perfschema/unittest/pfs-t.cc
+++ b/storage/perfschema/unittest/pfs-t.cc
@@ -37,14 +37,25 @@ PFS_file* lookup_file_by_name(const char* name)
uint i;
PFS_file *pfs;
uint len= strlen(name);
+ size_t dirlen;
+ const char *filename;
+ uint filename_length;;
for (i= 0; i < file_max; i++)
{
pfs= & file_array[i];
if (pfs->m_lock.is_populated())
{
- if ((len == pfs->m_filename_length) &&
- (strncmp(name, pfs->m_filename, pfs->m_filename_length) == 0))
+ /*
+ When a file "foo" is instrumented, the name is normalized
+ to "/path/to/current/directory/foo", so we remove the
+ directory name here to find it back.
+ */
+ dirlen= dirname_length(pfs->m_filename);
+ filename= pfs->m_filename + dirlen;
+ filename_length= pfs->m_filename_length - dirlen;
+ if ((len == filename_length) &&
+ (strncmp(name, filename, filename_length) == 0))
return pfs;
}
}