~ubuntu-branches/ubuntu/vivid/mariadb-5.5/vivid

« back to all changes in this revision

Viewing changes to storage/tokudb/ft-index/src/tests/test_4015.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
/*
 
4
COPYING CONDITIONS NOTICE:
 
5
 
 
6
  This program is free software; you can redistribute it and/or modify
 
7
  it under the terms of version 2 of the GNU General Public License as
 
8
  published by the Free Software Foundation, and provided that the
 
9
  following conditions are met:
 
10
 
 
11
      * Redistributions of source code must retain this COPYING
 
12
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
13
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
14
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
15
        GRANT (below).
 
16
 
 
17
      * Redistributions in binary form must reproduce this COPYING
 
18
        CONDITIONS NOTICE, the COPYRIGHT NOTICE (below), the
 
19
        DISCLAIMER (below), the UNIVERSITY PATENT NOTICE (below), the
 
20
        PATENT MARKING NOTICE (below), and the PATENT RIGHTS
 
21
        GRANT (below) in the documentation and/or other materials
 
22
        provided with the distribution.
 
23
 
 
24
  You should have received a copy of the GNU General Public License
 
25
  along with this program; if not, write to the Free Software
 
26
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 
27
  02110-1301, USA.
 
28
 
 
29
COPYRIGHT NOTICE:
 
30
 
 
31
  TokuDB, Tokutek Fractal Tree Indexing Library.
 
32
  Copyright (C) 2007-2013 Tokutek, Inc.
 
33
 
 
34
DISCLAIMER:
 
35
 
 
36
  This program is distributed in the hope that it will be useful, but
 
37
  WITHOUT ANY WARRANTY; without even the implied warranty of
 
38
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
39
  General Public License for more details.
 
40
 
 
41
UNIVERSITY PATENT NOTICE:
 
42
 
 
43
  The technology is licensed by the Massachusetts Institute of
 
44
  Technology, Rutgers State University of New Jersey, and the Research
 
45
  Foundation of State University of New York at Stony Brook under
 
46
  United States of America Serial No. 11/760379 and to the patents
 
47
  and/or patent applications resulting from it.
 
48
 
 
49
PATENT MARKING NOTICE:
 
50
 
 
51
  This software is covered by US Patent No. 8,185,551.
 
52
  This software is covered by US Patent No. 8,489,638.
 
53
 
 
54
PATENT RIGHTS GRANT:
 
55
 
 
56
  "THIS IMPLEMENTATION" means the copyrightable works distributed by
 
57
  Tokutek as part of the Fractal Tree project.
 
58
 
 
59
  "PATENT CLAIMS" means the claims of patents that are owned or
 
60
  licensable by Tokutek, both currently or in the future; and that in
 
61
  the absence of this license would be infringed by THIS
 
62
  IMPLEMENTATION or by using or running THIS IMPLEMENTATION.
 
63
 
 
64
  "PATENT CHALLENGE" shall mean a challenge to the validity,
 
65
  patentability, enforceability and/or non-infringement of any of the
 
66
  PATENT CLAIMS or otherwise opposing any of the PATENT CLAIMS.
 
67
 
 
68
  Tokutek hereby grants to you, for the term and geographical scope of
 
69
  the PATENT CLAIMS, a non-exclusive, no-charge, royalty-free,
 
70
  irrevocable (except as stated in this section) patent license to
 
71
  make, have made, use, offer to sell, sell, import, transfer, and
 
72
  otherwise run, modify, and propagate the contents of THIS
 
73
  IMPLEMENTATION, where such license applies only to the PATENT
 
74
  CLAIMS.  This grant does not include claims that would be infringed
 
75
  only as a consequence of further modifications of THIS
 
76
  IMPLEMENTATION.  If you or your agent or licensee institute or order
 
77
  or agree to the institution of patent litigation against any entity
 
78
  (including a cross-claim or counterclaim in a lawsuit) alleging that
 
79
  THIS IMPLEMENTATION constitutes direct or contributory patent
 
80
  infringement, or inducement of patent infringement, then any rights
 
81
  granted to you under this License shall terminate as of the date
 
82
  such litigation is filed.  If you or your agent or exclusive
 
83
  licensee institute or order or agree to the institution of a PATENT
 
84
  CHALLENGE, then Tokutek may terminate any rights granted to you
 
85
  under this License.
 
86
*/
 
87
 
 
88
#ident "Copyright (c) 2011-2013 Tokutek Inc.  All rights reserved."
 
89
#ident "$Id$"
 
90
 
 
91
 
 
92
#include "test.h"
 
93
#include "toku_pthread.h"
 
94
#include <portability/toku_atomic.h>
 
95
 
 
96
static int my_compare (DB *db, const DBT *a, const DBT *b) {
 
97
    assert(db);
 
98
    assert(db->cmp_descriptor);
 
99
    assert(db->cmp_descriptor->dbt.size >= 3);
 
100
    char *CAST_FROM_VOIDP(data, db->cmp_descriptor->dbt.data);
 
101
    assert(data[0]=='f');
 
102
    assert(data[1]=='o');
 
103
    assert(data[2]=='o');
 
104
    if (verbose) printf("compare descriptor=%s\n", data);
 
105
    sched_yield();
 
106
    return uint_dbt_cmp(db, a, b);
 
107
}
 
108
 
 
109
DB_ENV *env;
 
110
DB     *db;
 
111
const char   *env_dir = TOKU_TEST_FILENAME;
 
112
volatile int done = 0;
 
113
 
 
114
static void *startA (void *ignore __attribute__((__unused__))) {
 
115
    for (int i=0;i<999; i++) {
 
116
        DBT k,v;
 
117
        int a = (random()<<16) + i;
 
118
        dbt_init(&k, &a, sizeof(a));
 
119
        dbt_init(&v, &a, sizeof(a));
 
120
        DB_TXN *txn;
 
121
    again:
 
122
        { int chk_r = env->txn_begin(env, NULL, &txn, DB_TXN_NOSYNC); CKERR(chk_r); }
 
123
        {
 
124
            int r = db->put(db, txn, &k, &v, 0);
 
125
            if (r==DB_LOCK_NOTGRANTED) {
 
126
                if (verbose) printf("lock not granted on %d\n", i);
 
127
                { int chk_r = txn->abort(txn); CKERR(chk_r); }
 
128
                goto again;
 
129
            }
 
130
            assert(r==0);
 
131
        }
 
132
        { int chk_r = txn->commit(txn, 0); CKERR(chk_r); }
 
133
    }
 
134
    int r __attribute__((__unused__)) = toku_sync_fetch_and_add(&done, 1);
 
135
    return NULL;
 
136
}
 
137
static void change_descriptor (DB_TXN *txn, int i) {
 
138
    DBT desc;
 
139
    char foo[100];
 
140
    snprintf(foo, 99, "foo%d", i);
 
141
    dbt_init(&desc, foo, 1+strlen(foo));
 
142
    int r;
 
143
    if (verbose) printf("trying to change to %s\n", foo);
 
144
    while ((r=db->change_descriptor(db, txn, &desc, 0))) {
 
145
        if (verbose) printf("Change failed r=%d, try again\n", r);
 
146
    }
 
147
    if (verbose) printf("ok\n");
 
148
}
 
149
static void startB (void) {
 
150
    for (int i=0; !done; i++) {
 
151
        IN_TXN_COMMIT(env, NULL, txn, 0,
 
152
                      change_descriptor(txn, i));
 
153
        sched_yield();
 
154
    }
 
155
}
 
156
 
 
157
static void my_parse_args (int argc, char * const argv[]) {
 
158
    const char *argv0=argv[0];
 
159
    while (argc>1) {
 
160
        int resultcode=0;
 
161
        if (strcmp(argv[1], "-v")==0) {
 
162
            verbose++;
 
163
        } else if (strcmp(argv[1],"-q")==0) {
 
164
            verbose--;
 
165
            if (verbose<0) verbose=0;
 
166
        } else if (strcmp(argv[1],"--envdir")==0) {
 
167
            assert(argc>2);
 
168
            env_dir = argv[2];
 
169
            argc--;
 
170
            argv++;
 
171
        } else if (strcmp(argv[1], "-h")==0) {
 
172
        do_usage:
 
173
            fprintf(stderr, "Usage:\n%s [-v|-q] [-h] [--envdir <envdir>]\n", argv0);
 
174
            exit(resultcode);
 
175
        } else {
 
176
            resultcode=1;
 
177
            goto do_usage;
 
178
        }
 
179
        argc--;
 
180
        argv++;
 
181
    }
 
182
}
 
183
 
 
184
int test_main(int argc, char * const argv[]) {
 
185
    my_parse_args(argc, argv);
 
186
 
 
187
    db_env_set_num_bucket_mutexes(32);
 
188
    { int chk_r = db_env_create(&env, 0); CKERR(chk_r); }
 
189
    { int chk_r = env->set_redzone(env, 0); CKERR(chk_r); }
 
190
    { int chk_r = env->set_default_bt_compare(env, my_compare); CKERR(chk_r); }
 
191
    {
 
192
        const int size = 10+strlen(env_dir);
 
193
        char cmd[size];
 
194
        snprintf(cmd, size, "rm -rf %s", env_dir);
 
195
        int r = system(cmd);
 
196
        CKERR(r);
 
197
    }
 
198
    { int chk_r = toku_os_mkdir(env_dir, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(chk_r); }
 
199
    const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE;
 
200
    { int chk_r = env->open(env, env_dir, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(chk_r); }
 
201
 
 
202
    { int chk_r = db_create(&db, env, 0); CKERR(chk_r); }
 
203
    { int chk_r = db->set_pagesize(db, 1024); CKERR(chk_r); }
 
204
    { int chk_r = db->open(db, NULL, "db", NULL, DB_BTREE, DB_CREATE, 0666); CKERR(chk_r); }
 
205
    DBT desc;
 
206
    dbt_init(&desc, "foo", sizeof("foo"));
 
207
    IN_TXN_COMMIT(env, NULL, txn, 0,
 
208
                  { int chk_r = db->change_descriptor(db, txn, &desc, DB_UPDATE_CMP_DESCRIPTOR); CKERR(chk_r); });
 
209
    pthread_t thd;
 
210
    { int chk_r = toku_pthread_create(&thd, NULL, startA, NULL); CKERR(chk_r); }
 
211
 
 
212
    startB();
 
213
 
 
214
    void *retval;
 
215
    { int chk_r = toku_pthread_join(thd, &retval); CKERR(chk_r); }
 
216
    assert(retval==NULL);
 
217
 
 
218
    { int chk_r = db->close(db, 0); CKERR(chk_r); }
 
219
 
 
220
 
 
221
    { int chk_r = env->close(env, 0); CKERR(chk_r); }
 
222
 
 
223
    return 0;
 
224
}