~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/ft/tests/verify-bad-msn.cc

  • Committer: Package Import Robot
  • Author(s): James Page, Otto Kekäläinen
  • Date: 2014-02-17 16:51:52 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140217165152-k315d3175g865kkx
Tags: 5.5.35-1
[ Otto Kekäläinen ]
* New upstream release, fixing the following security issues:
  - Buffer overflow in client/mysql.cc (Closes: #737597).
    - CVE-2014-0001
  - http://www.oracle.com/technetwork/topics/security/cpujan2014-1972949.html
    - CVE-2013-5891
    - CVE-2013-5908
    - CVE-2014-0386
    - CVE-2014-0393
    - CVE-2014-0401
    - CVE-2014-0402
    - CVE-2014-0412
    - CVE-2014-0420
    - CVE-2014-0437
* Upstream https://mariadb.atlassian.net/browse/MDEV-4902
  fixes compatibility with Bison 3.0 (Closes: #733002)
* Updated Russian debconf translation (Closes: #734426)
* Updated Japanese debconf translation (Closes: #735284)
* Updated French debconf translation (Closes: #736480)
* Renamed SONAME properly (Closes: #732967)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
 
2
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
 
3
#ident "$Id$"
 
4
/*
 
5
COPYING CONDITIONS NOTICE:
 
6
 
 
7
  This program is free software; you can redistribute it and/or modify
 
8
  it under the terms of version 2 of the GNU General Public License as
 
9
  published by the Free Software Foundation, and provided that the
 
10
  following conditions are met:
 
11
 
 
12
      * Redistributions of source code must retain this COPYING
 
13
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
14
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
15
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
16
        GRANT (below).
 
17
 
 
18
      * Redistributions in binary form must reproduce this COPYING
 
19
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
20
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
21
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
22
        GRANT (below) in the documentation and/or other materials
 
23
        provided with the distribution.
 
24
 
 
25
  You should have received a copy of the GNU General Public License
 
26
  along with this program; if not, write to the Free Software
 
27
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
28
  02110-1301, USA.
 
29
 
 
30
COPYRIGHT NOTICE:
 
31
 
 
32
  TokuDB, Tokutek Fractal Tree Indexing Library.
 
33
  Copyright (C) 2007-2013 Tokutek, Inc.
 
34
 
 
35
DISCLAIMER:
 
36
 
 
37
  This program is distributed in the hope that it will be useful, but
 
38
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
39
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
40
  General Public License for more details.
 
41
 
 
42
UNIVERSITY PATENT NOTICE:
 
43
 
 
44
  The technology is licensed by the Massachusetts Institute of
 
45
  Technology, Rutgers State University of New Jersey, and the Research
 
46
  Foundation of State University of New York at Stony Brook under
 
47
  United States of America Serial No. 11/760379 and to the patents
 
48
  and/or patent applications resulting from it.
 
49
 
 
50
PATENT MARKING NOTICE:
 
51
 
 
52
  This software is covered by US Patent No. 8,185,551.
 
53
  This software is covered by US Patent No. 8,489,638.
 
54
 
 
55
PATENT RIGHTS GRANT:
 
56
 
 
57
  "THIS IMPLEMENTATION" means the copyrightable works distributed by
 
58
  Tokutek as part of the Fractal Tree project.
 
59
 
 
60
  "PATENT CLAIMS" means the claims of patents that are owned or
 
61
  licensable by Tokutek, both currently or in the future; and that in
 
62
  the absence of this license would be infringed by THIS
 
63
  IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
 
64
 
 
65
  "PATENT CHALLENGE" shall mean a challenge to the validity,
 
66
  patentability, enforceability and/or non-infringement of any of the
 
67
  PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
 
68
 
 
69
  Tokutek hereby grants to you, for the term and geographical scope of
 
70
  the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
 
71
  irrevocable (except as stated in this section) patent license to
 
72
  make, have made, use, offer to sell, sell, import, transfer, and
 
73
  otherwise run, modify, and propagate the contents of THIS
 
74
  IMPLEMENTATION, where such license applies only to the PATENT
 
75
  CLAIMS.  This grant does not include claims that would be infringed
 
76
  only as a consequence of further modifications of THIS
 
77
  IMPLEMENTATION.  If you or your agent or licensee institute or order
 
78
  or agree to the institution of patent litigation against any entity
 
79
  (including a cross-claim or counterclaim in a lawsuit) alleging that
 
80
  THIS IMPLEMENTATION constitutes direct or contributory patent
 
81
  infringement, or inducement of patent infringement, then any rights
 
82
  granted to you under this License shall terminate as of the date
 
83
  such litigation is filed.  If you or your agent or exclusive
 
84
  licensee institute or order or agree to the institution of a PATENT
 
85
  CHALLENGE, then Tokutek may terminate any rights granted to you
 
86
  under this License.
 
87
*/
 
88
 
 
89
#ident "Copyright (c) 2011-2013 Tokutek Inc.  All rights reserved."
 
90
 
 
91
// generate fractal trees with a given height, fanout, and number of leaf elements per leaf.
 
92
// jam the child buffers with inserts.
 
93
// this code can be used as a template to build broken trees
 
94
//
 
95
// This program (copied from make-tree.c) creates a tree with bad msns by commenting out
 
96
// the setting of the msn:
 
97
//
 
98
// To correctly set msn per node:
 
99
//  - set in each non-leaf when message is injected into node (see insert_into_child_buffer())
 
100
//  - set in each leaf node (see append_leaf())
 
101
//  - set in root node (set test_make_tree())
 
102
 
 
103
 
 
104
 
 
105
#include <ft-cachetable-wrappers.h>
 
106
#include "test.h"
 
107
 
 
108
static FTNODE
 
109
make_node(FT_HANDLE brt, int height) {
 
110
    FTNODE node = NULL;
 
111
    int n_children = (height == 0) ? 1 : 0;
 
112
    toku_create_new_ftnode(brt, &node, height, n_children);
 
113
    if (n_children) BP_STATE(node,0) = PT_AVAIL;
 
114
    return node;
 
115
}
 
116
 
 
117
static void
 
118
append_leaf(FTNODE leafnode, void *key, size_t keylen, void *val, size_t vallen) {
 
119
    assert(leafnode->height == 0);
 
120
 
 
121
    DBT thekey; toku_fill_dbt(&thekey, key, keylen);
 
122
    DBT theval; toku_fill_dbt(&theval, val, vallen);
 
123
 
 
124
    // get an index that we can use to create a new leaf entry
 
125
    uint32_t idx = BLB_DATA(leafnode, 0)->omt_size();
 
126
 
 
127
    MSN msn = next_dummymsn();
 
128
 
 
129
    // apply an insert to the leaf node
 
130
    FT_MSG_S cmd = { FT_INSERT, msn, xids_get_root_xids(), .u={.id = { &thekey, &theval }} };
 
131
    toku_ft_bn_apply_cmd_once(BLB(leafnode, 0), &cmd, idx, NULL, TXNID_NONE, make_gc_info(false), NULL, NULL);
 
132
 
 
133
    // Create bad tree (don't do following):
 
134
    // leafnode->max_msn_applied_to_node = msn;
 
135
 
 
136
    // dont forget to dirty the node
 
137
    leafnode->dirty = 1;
 
138
}
 
139
 
 
140
static void
 
141
populate_leaf(FTNODE leafnode, int seq, int n, int *minkey, int *maxkey) {
 
142
    for (int i = 0; i < n; i++) {
 
143
        int k = htonl(seq + i);
 
144
        int v = seq + i;
 
145
        append_leaf(leafnode, &k, sizeof k, &v, sizeof v);
 
146
    }
 
147
    *minkey = htonl(seq);
 
148
    *maxkey = htonl(seq + n - 1);
 
149
}
 
150
 
 
151
static void
 
152
insert_into_child_buffer(FT_HANDLE brt, FTNODE node, int childnum, int minkey, int maxkey) {
 
153
    for (unsigned int val = htonl(minkey); val <= htonl(maxkey); val++) {
 
154
        MSN msn = next_dummymsn();
 
155
        unsigned int key = htonl(val);
 
156
        DBT thekey; toku_fill_dbt(&thekey, &key, sizeof key);
 
157
        DBT theval; toku_fill_dbt(&theval, &val, sizeof val);
 
158
        toku_ft_append_to_child_buffer(brt->ft->compare_fun, NULL, node, childnum, FT_INSERT, msn, xids_get_root_xids(), true, &thekey, &theval);
 
159
 
 
160
        // Create bad tree (don't do following):
 
161
        // node->max_msn_applied_to_node = msn;
 
162
    }
 
163
}
 
164
 
 
165
static FTNODE
 
166
make_tree(FT_HANDLE brt, int height, int fanout, int nperleaf, int *seq, int *minkey, int *maxkey) {
 
167
    FTNODE node;
 
168
    if (height == 0) {
 
169
        node = make_node(brt, 0);
 
170
        populate_leaf(node, *seq, nperleaf, minkey, maxkey);
 
171
        *seq += nperleaf;
 
172
    } else {
 
173
        node = make_node(brt, height);
 
174
        int minkeys[fanout], maxkeys[fanout];
 
175
        for (int childnum = 0; childnum < fanout; childnum++) {
 
176
            FTNODE child = make_tree(brt, height-1, fanout, nperleaf, seq, &minkeys[childnum], &maxkeys[childnum]);
 
177
            if (childnum == 0) {
 
178
                toku_ft_nonleaf_append_child(node, child, NULL);
 
179
            } else {
 
180
                int k = maxkeys[childnum-1]; // use the max of the left tree
 
181
                DBT pivotkey;
 
182
                toku_ft_nonleaf_append_child(node, child, toku_fill_dbt(&pivotkey, &k, sizeof k));
 
183
            }
 
184
            toku_unpin_ftnode(brt->ft, child);
 
185
            insert_into_child_buffer(brt, node, childnum, minkeys[childnum], maxkeys[childnum]);
 
186
        }
 
187
        *minkey = minkeys[0];
 
188
        *maxkey = maxkeys[0];
 
189
        for (int i = 1; i < fanout; i++) {
 
190
            if (memcmp(minkey, &minkeys[i], sizeof minkeys[i]) > 0)
 
191
                *minkey = minkeys[i];
 
192
            if (memcmp(maxkey, &maxkeys[i], sizeof maxkeys[i]) < 0)
 
193
                *maxkey = maxkeys[i];
 
194
        }
 
195
    }
 
196
    return node;
 
197
}
 
198
 
 
199
static UU() void
 
200
deleted_row(UU() DB *db, UU() DBT *key, UU() DBT *val) {
 
201
}
 
202
 
 
203
static void 
 
204
test_make_tree(int height, int fanout, int nperleaf, int do_verify) {
 
205
    int r;
 
206
 
 
207
    // cleanup
 
208
    const char *fname = TOKU_TEST_FILENAME;
 
209
    r = unlink(fname);
 
210
    assert(r == 0 || (r == -1 && errno == ENOENT));
 
211
 
 
212
    // create a cachetable
 
213
    CACHETABLE ct = NULL;
 
214
    toku_cachetable_create(&ct, 0, ZERO_LSN, NULL_LOGGER);
 
215
 
 
216
    // create the brt
 
217
    TOKUTXN null_txn = NULL;
 
218
    FT_HANDLE brt = NULL;
 
219
    r = toku_open_ft_handle(fname, 1, &brt, 1024, 256, TOKU_DEFAULT_COMPRESSION_METHOD, ct, null_txn, toku_builtin_compare_fun);
 
220
    assert(r == 0);
 
221
 
 
222
    // make a tree
 
223
    int seq = 0, minkey, maxkey;
 
224
    FTNODE newroot = make_tree(brt, height, fanout, nperleaf, &seq, &minkey, &maxkey);
 
225
 
 
226
    // set the new root to point to the new tree
 
227
    toku_ft_set_new_root_blocknum(brt->ft, newroot->thisnodename);
 
228
 
 
229
    // Create bad tree (don't do following):
 
230
    // newroot->max_msn_applied_to_node = last_dummymsn(); // capture msn of last message injected into tree
 
231
 
 
232
    // unpin the new root
 
233
    toku_unpin_ftnode(brt->ft, newroot);
 
234
 
 
235
    if (do_verify) {
 
236
        r = toku_verify_ft(brt);
 
237
        assert(r != 0);
 
238
    }
 
239
 
 
240
    // flush to the file system
 
241
    r = toku_close_ft_handle_nolsn(brt, 0);     
 
242
    assert(r == 0);
 
243
 
 
244
    // shutdown the cachetable
 
245
    toku_cachetable_close(&ct);
 
246
}
 
247
 
 
248
static int
 
249
usage(void) {
 
250
    return 1;
 
251
}
 
252
 
 
253
int
 
254
test_main (int argc , const char *argv[]) {
 
255
    initialize_dummymsn();
 
256
    int height = 1;
 
257
    int fanout = 2;
 
258
    int nperleaf = 8;
 
259
    int do_verify = 1;
 
260
    for (int i = 1; i < argc; i++) {
 
261
        const char *arg = argv[i];
 
262
        if (strcmp(arg, "-v") == 0) {
 
263
            verbose++;
 
264
            continue;
 
265
        }
 
266
        if (strcmp(arg, "-q") == 0) {
 
267
            verbose = 0;
 
268
            continue;
 
269
        }
 
270
        if (strcmp(arg, "--height") == 0 && i+1 < argc) {
 
271
            height = atoi(argv[++i]);
 
272
            continue;
 
273
        }
 
274
        if (strcmp(arg, "--fanout") == 0 && i+1 < argc) {
 
275
            fanout = atoi(argv[++i]);
 
276
            continue;
 
277
        }
 
278
        if (strcmp(arg, "--nperleaf") == 0 && i+1 < argc) {
 
279
            nperleaf = atoi(argv[++i]);
 
280
            continue;
 
281
        }
 
282
        if (strcmp(arg, "--verify") == 0 && i+1 < argc) {
 
283
            do_verify = atoi(argv[++i]);
 
284
            continue;
 
285
        }
 
286
        return usage();
 
287
    }
 
288
    test_make_tree(height, fanout, nperleaf, do_verify);
 
289
    return 0;
 
290
}