1/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15
16#include <my_global.h>
17#include <pfs_instr.h>
18#include <pfs_stat.h>
19#include <pfs_global.h>
20#include <pfs_instr_class.h>
21#include <tap.h>
22
23#include <memory.h>
24
25void test_digest_length_overflow()
26{
27 if (sizeof(size_t) != 4)
28 {
29 skip(2, "digest length overflow requires a 32-bit environment");
30 return;
31 }
32
33 PFS_global_param param;
34 memset(&param, 0, sizeof(param));
35 param.m_enabled= true;
36 /*
37 Force 32-bit arithmetic overflow using the digest memory allocation
38 parameters. The Performance Schema should detect the overflow, free
39 allocated memory and abort initialization with a warning.
40 */
41
42 /* Max digest length, events_statements_history_long. */
43 param.m_events_statements_history_long_sizing= 10000;
44 param.m_digest_sizing= 1000;
45 param.m_max_digest_length= (1024 * 1024);
46 pfs_max_digest_length= param.m_max_digest_length;
47
48 int rc = init_events_statements_history_long(param.m_events_statements_history_long_sizing);
49 ok(rc == 1, "digest length overflow (init_events_statements_history_long");
50
51 /* Max digest length, events_statements_summary_by_digest. */
52 param.m_max_digest_length= (1024 * 1024);
53 param.m_digest_sizing= 10000;
54
55 rc = init_digest(&param);
56 ok(rc == 1, "digest length overflow (init_digest)");
57}
58
59void do_all_tests()
60{
61 test_digest_length_overflow();
62}
63
64int main(int, char **)
65{
66 plan(2);
67 MY_INIT("pfs_misc-t");
68 do_all_tests();
69 my_end(0);
70 return (exit_status());
71}
72
73