summaryrefslogtreecommitdiff
path: root/storage/perfschema/unittest
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-08-03 13:05:40 +0200
committerSergei Golubchik <serg@mariadb.org>2015-08-03 13:05:40 +0200
commit167c540048ed1c49fa97f86cadba1e7ff0559d12 (patch)
tree990742a8ccd6c994aa14c5ac4ace40af0ef23cee /storage/perfschema/unittest
parent3c3724991e4ce802f79a8dbee2f72e3073729f2f (diff)
downloadmariadb-git-167c540048ed1c49fa97f86cadba1e7ff0559d12.tar.gz
5.6.26
Diffstat (limited to 'storage/perfschema/unittest')
-rw-r--r--storage/perfschema/unittest/CMakeLists.txt1
-rw-r--r--storage/perfschema/unittest/pfs_misc-t.cc71
-rw-r--r--storage/perfschema/unittest/stub_pfs_global.h24
-rw-r--r--storage/perfschema/unittest/stub_print_error.h19
4 files changed, 113 insertions, 2 deletions
diff --git a/storage/perfschema/unittest/CMakeLists.txt b/storage/perfschema/unittest/CMakeLists.txt
index b4f1c58181c..22e4aad3f36 100644
--- a/storage/perfschema/unittest/CMakeLists.txt
+++ b/storage/perfschema/unittest/CMakeLists.txt
@@ -42,6 +42,7 @@ SET(tests
pfs_host-oom
pfs_user-oom
pfs
+ pfs_misc
)
FOREACH(testname ${tests})
PFS_ADD_TEST(${testname})
diff --git a/storage/perfschema/unittest/pfs_misc-t.cc b/storage/perfschema/unittest/pfs_misc-t.cc
new file mode 100644
index 00000000000..a0fff2f593c
--- /dev/null
+++ b/storage/perfschema/unittest/pfs_misc-t.cc
@@ -0,0 +1,71 @@
+/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
+
+#include <my_global.h>
+#include <pfs_instr.h>
+#include <pfs_stat.h>
+#include <pfs_global.h>
+#include <pfs_instr_class.h>
+#include <tap.h>
+
+#include <memory.h>
+
+void test_digest_length_overflow()
+{
+ if (sizeof(size_t) != 4)
+ {
+ skip(2, "digest length overflow requires a 32-bit environment");
+ return;
+ }
+
+ PFS_global_param param;
+ memset(&param, 0, sizeof(param));
+ param.m_enabled= true;
+ /*
+ Force 32-bit arithmetic overflow using the digest memory allocation
+ parameters. The Performance Schema should detect the overflow, free
+ allocated memory and abort initialization with a warning.
+ */
+
+ /* Max digest length, events_statements_history_long. */
+ param.m_events_statements_history_long_sizing= 10000;
+ param.m_digest_sizing= 1000;
+ param.m_max_digest_length= (1024 * 1024);
+ pfs_max_digest_length= param.m_max_digest_length;
+
+ int rc = init_events_statements_history_long(param.m_events_statements_history_long_sizing);
+ ok(rc == 1, "digest length overflow (init_events_statements_history_long");
+
+ /* Max digest length, events_statements_summary_by_digest. */
+ param.m_max_digest_length= (1024 * 1024);
+ param.m_digest_sizing= 10000;
+
+ rc = init_digest(&param);
+ ok(rc == 1, "digest length overflow (init_digest)");
+}
+
+void do_all_tests()
+{
+ test_digest_length_overflow();
+}
+
+int main(int, char **)
+{
+ plan(2);
+ MY_INIT("pfs_misc-t");
+ do_all_tests();
+ return exit_status();
+}
+
diff --git a/storage/perfschema/unittest/stub_pfs_global.h b/storage/perfschema/unittest/stub_pfs_global.h
index 34c52e18b5a..8f204006f48 100644
--- a/storage/perfschema/unittest/stub_pfs_global.h
+++ b/storage/perfschema/unittest/stub_pfs_global.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -25,6 +25,11 @@ int stub_alloc_fails_after_count= 0;
void *pfs_malloc(size_t size, myf)
{
+ /*
+ Catch non initialized sizing parameter in the unit tests.
+ */
+ DBUG_ASSERT(size <= 100*1024*1024);
+
if (stub_alloc_always_fails)
return NULL;
@@ -43,6 +48,23 @@ void pfs_free(void *ptr)
free(ptr);
}
+void *pfs_malloc_array(size_t n, size_t size, myf flags)
+{
+ size_t array_size= n * size;
+ /* Check for overflow before allocating. */
+ if (is_overflow(array_size, n, size))
+ return NULL;
+ return pfs_malloc(array_size, flags);
+}
+
+bool is_overflow(size_t product, size_t n1, size_t n2)
+{
+ if (n1 != 0 && (product / n1 != n2))
+ return true;
+ else
+ return false;
+}
+
void pfs_print_error(const char *format, ...)
{
}
diff --git a/storage/perfschema/unittest/stub_print_error.h b/storage/perfschema/unittest/stub_print_error.h
index caad24e5257..e9b8bc25548 100644
--- a/storage/perfschema/unittest/stub_print_error.h
+++ b/storage/perfschema/unittest/stub_print_error.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+/* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -33,6 +33,23 @@ void pfs_free(void *ptr)
free(ptr);
}
+void *pfs_malloc_array(size_t n, size_t size, myf flags)
+{
+ size_t array_size= n * size;
+ /* Check for overflow before allocating. */
+ if (is_overflow(array_size, n, size))
+ return NULL;
+ return pfs_malloc(array_size, flags);
+}
+
+bool is_overflow(size_t product, size_t n1, size_t n2)
+{
+ if (n1 != 0 && (product / n1 != n2))
+ return true;
+ else
+ return false;
+}
+
void pfs_print_error(const char *format, ...)
{
/* Do not pollute the unit test output with annoying messages. */