~ubuntu-branches/ubuntu/utopic/mariadb-5.5/utopic-security

« back to all changes in this revision

Viewing changes to storage/tokudb/hatoku_cmp.cc

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2014-04-17 20:55:22 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140417205522-wof4l36nxhlkn89m
* New upstream release, fixing the following security issues:
  * Corresponding MariaDB CVEs for Oracle SPU April 2014 (Closes: #745330)
    - CVE-2014-0384 
    - CVE-2014-2419 
    - CVE-2014-2430 
    - CVE-2014-2431 
    - CVE-2014-2432 
    - CVE-2014-2436 
    - CVE-2014-2438 
    - CVE-2014-2440
* Re-enabled TokuDB with "if arch amd64" in d/rules
* Applied patch to log init output better
  (Closes https://mariadb.atlassian.net/browse/MDEV-5957)

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
// in a TokuDB table. The non-valid fields are those
99
99
// that have been deprecated since before 5.1, and can
100
100
// only exist through upgrades of old versions of MySQL
101
 
bool field_valid_for_tokudb_table(Field* field) {
 
101
static bool field_valid_for_tokudb_table(Field* field) {
102
102
    bool ret_val = false;
103
103
    enum_field_types mysql_type = field->real_type();
104
104
    switch (mysql_type) {
117
117
    case MYSQL_TYPE_TIMESTAMP:
118
118
    case MYSQL_TYPE_DOUBLE:
119
119
    case MYSQL_TYPE_FLOAT:
120
 
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699
 
120
#if (50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \
 
121
    (50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) || \
 
122
    (100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099)
121
123
    case MYSQL_TYPE_DATETIME2:
122
124
    case MYSQL_TYPE_TIMESTAMP2:
123
125
    case MYSQL_TYPE_TIME2:
149
151
    return ret_val;
150
152
}
151
153
 
152
 
void get_var_field_info(
 
154
static void get_var_field_info(
153
155
    uint32_t* field_len, // output: length of field
154
156
    uint32_t* start_offset, // output, length of offset where data starts
155
157
    uint32_t var_field_index, //input, index of var field we want info on
193
195
    *field_len = data_end_offset - data_start_offset;
194
196
}
195
197
 
196
 
void get_blob_field_info(
 
198
static void get_blob_field_info(
197
199
    uint32_t* start_offset, 
198
200
    uint32_t len_of_offsets,
199
201
    const uchar* var_field_data_ptr, 
229
231
 
230
232
// this function is pattern matched from 
231
233
// InnoDB's get_innobase_type_from_mysql_type
232
 
TOKU_TYPE mysql_to_toku_type (Field* field) {
 
234
static TOKU_TYPE mysql_to_toku_type (Field* field) {
233
235
    TOKU_TYPE ret_val = toku_type_unknown;
234
236
    enum_field_types mysql_type = field->real_type();
235
237
    switch (mysql_type) {
264
266
    case MYSQL_TYPE_FLOAT:
265
267
        ret_val = toku_type_float;
266
268
        goto exit;
267
 
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699
 
269
#if (50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \
 
270
    (50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) || \
 
271
    (100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099)
268
272
    case MYSQL_TYPE_DATETIME2:
269
273
    case MYSQL_TYPE_TIMESTAMP2:
270
274
    case MYSQL_TYPE_TIME2:
424
428
            ret_val = a_num-b_num;
425
429
            goto exit;
426
430
        case (3):
427
 
            a_num = uint3korr(a_buf);
428
 
            b_num = uint3korr(b_buf);
 
431
            a_num = tokudb_uint3korr(a_buf);
 
432
            b_num = tokudb_uint3korr(b_buf);
429
433
            ret_val = a_num-b_num;
430
434
            goto exit;
431
435
        case (4):
614
618
//
615
619
// partially copied from below
616
620
//
617
 
uchar* pack_toku_varbinary_from_desc(
 
621
static uchar* pack_toku_varbinary_from_desc(
618
622
    uchar* to_tokudb, 
619
623
    const uchar* from_desc, 
620
624
    uint32_t key_part_length, //number of bytes to use to encode the length in to_tokudb
659
663
        length = uint2korr(from_mysql);
660
664
        break;
661
665
    case (3):
662
 
        length = uint3korr(from_mysql);
 
666
        length = tokudb_uint3korr(from_mysql);
663
667
        break;
664
668
    case (4):
665
669
        length = uint4korr(from_mysql);
773
777
        length = uint2korr(from_mysql);
774
778
        break;
775
779
    case (3):
776
 
        length = uint3korr(from_mysql);
 
780
        length = tokudb_uint3korr(from_mysql);
777
781
        break;
778
782
    case (4):
779
783
        length = uint4korr(from_mysql);
854
858
//
855
859
// partially copied from below
856
860
//
857
 
uchar* pack_toku_varstring_from_desc(
 
861
static uchar* pack_toku_varstring_from_desc(
858
862
    uchar* to_tokudb, 
859
863
    const uchar* from_desc, 
860
864
    uint32_t key_part_length, //number of bytes to use to encode the length in to_tokudb
928
932
        length = uint2korr(from_mysql);
929
933
        break;
930
934
    case (3):
931
 
        length = uint3korr(from_mysql);
 
935
        length = tokudb_uint3korr(from_mysql);
932
936
        break;
933
937
    case (4):
934
938
        length = uint4korr(from_mysql);
1034
1038
//              created in create_toku_key_descriptor_for_key. The first
1035
1039
//              byte points to the TOKU_TYPE.
1036
1040
//
1037
 
uint32_t skip_field_in_descriptor(uchar* row_desc) {
 
1041
static uint32_t skip_field_in_descriptor(uchar* row_desc) {
1038
1042
    uchar* row_desc_pos = row_desc;
1039
1043
    TOKU_TYPE toku_type = (TOKU_TYPE)row_desc_pos[0];
1040
1044
    row_desc_pos++;
1069
1073
// to store the descriptor. Number of bytes used MUST match number of bytes
1070
1074
// we would skip in skip_field_in_descriptor
1071
1075
//
1072
 
int create_toku_key_descriptor_for_key(KEY* key, uchar* buf) {
 
1076
static int create_toku_key_descriptor_for_key(KEY* key, uchar* buf) {
1073
1077
    uchar* pos = buf;
1074
1078
    uint32_t num_bytes_in_field = 0;
1075
1079
    uint32_t charset_num = 0;
1174
1178
// to the descriptor, we can.
1175
1179
// 
1176
1180
//
1177
 
int create_toku_key_descriptor(
 
1181
static int create_toku_key_descriptor(
1178
1182
    uchar* buf, 
1179
1183
    bool is_first_hpk, 
1180
1184
    KEY* first_key, 
1350
1354
// packs a field from a  MySQL buffer into a tokudb buffer.
1351
1355
// Used for inserts/updates
1352
1356
//
1353
 
uchar* pack_toku_key_field(
 
1357
static uchar* pack_toku_key_field(
1354
1358
    uchar* to_tokudb,
1355
1359
    uchar* from_mysql,
1356
1360
    Field* field,
1443
1447
// use 2 bytes to encode the length, regardless of the field
1444
1448
// So varchar(4) will still use 2 bytes to encode the field
1445
1449
//
1446
 
uchar* pack_key_toku_key_field(
 
1450
static uchar* pack_key_toku_key_field(
1447
1451
    uchar* to_tokudb,
1448
1452
    uchar* from_mysql,
1449
1453
    Field* field,
1566
1570
}
1567
1571
 
1568
1572
 
1569
 
int tokudb_compare_two_keys(
 
1573
static int tokudb_compare_two_keys(
1570
1574
    const void* new_key_data, 
1571
1575
    const uint32_t new_key_size, 
1572
1576
    const void*  saved_key_data,
1700
1704
}
1701
1705
 
1702
1706
// comparison function to be used by the fractal trees.
1703
 
int tokudb_cmp_dbt_key(DB* file, const DBT *keya, const DBT *keyb) {
 
1707
static int tokudb_cmp_dbt_key(DB* file, const DBT *keya, const DBT *keyb) {
1704
1708
    int cmp;
1705
1709
    if (file->cmp_descriptor->dbt.size == 0) {
1706
1710
        cmp = simple_memcmp(keya, keyb);
1728
1732
}
1729
1733
 
1730
1734
//TODO: QQQ Only do one direction for prefix.
1731
 
int tokudb_prefix_cmp_dbt_key(DB *file, const DBT *keya, const DBT *keyb) {
 
1735
static int tokudb_prefix_cmp_dbt_key(DB *file, const DBT *keya, const DBT *keyb) {
1732
1736
    // calls to this function are done by the handlerton, and are
1733
1737
    // comparing just the keys as MySQL would compare them.
1734
1738
    bool read_string = false;
1848
1852
            max_parts);
1849
1853
}
1850
1854
 
1851
 
uint32_t create_toku_main_key_pack_descriptor (
 
1855
static uint32_t create_toku_main_key_pack_descriptor (
1852
1856
    uchar* buf
1853
1857
    ) 
1854
1858
{
1876
1880
    return pos - buf;
1877
1881
}
1878
1882
 
1879
 
#define COL_FIX_FIELD 0x11
1880
 
#define COL_VAR_FIELD 0x22
1881
 
#define COL_BLOB_FIELD 0x33
1882
 
 
1883
1883
#define COL_HAS_NO_CHARSET 0x44
1884
1884
#define COL_HAS_CHARSET 0x55
1885
1885
 
1897
1897
    pos += sizeof(uint32_t);
1898
1898
 
1899
1899
 
1900
 
uint32_t pack_desc_pk_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
 
1900
static uint32_t pack_desc_pk_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
1901
1901
    uchar* pos = buf;
1902
1902
    uint16 field_index = key_part->field->field_index;
1903
1903
    Field* field = table_share->field[field_index];
1942
1942
    return pos - buf;
1943
1943
}
1944
1944
 
1945
 
uint32_t pack_desc_pk_offset_info(
 
1945
static uint32_t pack_desc_pk_offset_info(
1946
1946
    uchar* buf, 
1947
1947
    KEY_AND_COL_INFO* kc_info, 
1948
1948
    TABLE_SHARE* table_share, 
1991
1991
    return pos - buf;
1992
1992
}
1993
1993
 
1994
 
uint32_t pack_desc_offset_info(uchar* buf, KEY_AND_COL_INFO* kc_info, uint pk_index, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
 
1994
static uint32_t pack_desc_offset_info(uchar* buf, KEY_AND_COL_INFO* kc_info, uint pk_index, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
1995
1995
    uchar* pos = buf;
1996
1996
    uint16 field_index = key_part->field->field_index;
1997
1997
    Field* field = table_share->field[field_index];
2040
2040
    return pos - buf;
2041
2041
}
2042
2042
 
2043
 
uint32_t pack_desc_key_length_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
 
2043
static uint32_t pack_desc_key_length_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
2044
2044
    uchar* pos = buf;
2045
2045
    uint16 field_index = key_part->field->field_index;
2046
2046
    Field* field = table_share->field[field_index];
2075
2075
    return pos - buf;
2076
2076
}
2077
2077
 
2078
 
uint32_t pack_desc_char_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
 
2078
static uint32_t pack_desc_char_info(uchar* buf, KEY_AND_COL_INFO* kc_info, TABLE_SHARE* table_share, KEY_PART_INFO* key_part) {
2079
2079
    uchar* pos = buf;
2080
2080
    uint16 field_index = key_part->field->field_index;
2081
2081
    Field* field = table_share->field[field_index];
2112
2112
    return pos - buf;
2113
2113
}
2114
2114
 
2115
 
uint32_t pack_some_row_info (
 
2115
static uint32_t pack_some_row_info (
2116
2116
    uchar* buf,
2117
2117
    uint pk_index,
2118
2118
    TABLE_SHARE* table_share,
2141
2141
    return pos - buf;
2142
2142
}
2143
2143
 
2144
 
uint32_t get_max_clustering_val_pack_desc_size(
 
2144
static uint32_t get_max_clustering_val_pack_desc_size(
2145
2145
    TABLE_SHARE* table_share
2146
2146
    ) 
2147
2147
{
2168
2168
    return ret_val;
2169
2169
}
2170
2170
 
2171
 
uint32_t create_toku_clustering_val_pack_descriptor (
 
2171
static uint32_t create_toku_clustering_val_pack_descriptor (
2172
2172
    uchar* buf,
2173
2173
    uint pk_index,
2174
2174
    TABLE_SHARE* table_share,
2227
2227
    last_col = 0;
2228
2228
    for (uint i = 0; i < table_share->fields; i++) {
2229
2229
        bool col_filtered = bitmap_is_set(&kc_info->key_filters[keynr],i);
2230
 
        if (kc_info->field_lengths[i] == 0) {
 
2230
        if (!is_fixed_field(kc_info, i)) {
2231
2231
            //
2232
2232
            // not a fixed field, continue
2233
2233
            //
2274
2274
    last_col = 0;
2275
2275
    for (uint i = 0; i < table_share->fields; i++) {
2276
2276
        bool col_filtered = bitmap_is_set(&kc_info->key_filters[keynr],i);
2277
 
        if (kc_info->length_bytes[i] == 0) {
 
2277
        if (!is_variable_field(kc_info, i)) {
2278
2278
            //
2279
2279
            // not a var field, continue
2280
2280
            //
2322
2322
    return pos - buf;
2323
2323
}
2324
2324
 
2325
 
uint32_t pack_clustering_val_from_desc(
 
2325
static uint32_t pack_clustering_val_from_desc(
2326
2326
    uchar* buf,
2327
2327
    void* row_desc,
2328
2328
    uint32_t row_desc_size,
2476
2476
}
2477
2477
 
2478
2478
 
2479
 
uint32_t get_max_secondary_key_pack_desc_size(
 
2479
static uint32_t get_max_secondary_key_pack_desc_size(
2480
2480
    KEY_AND_COL_INFO* kc_info
2481
2481
    ) 
2482
2482
{
2515
2515
    return ret_val;
2516
2516
}
2517
2517
 
2518
 
uint32_t create_toku_secondary_key_pack_descriptor (
 
2518
static uint32_t create_toku_secondary_key_pack_descriptor (
2519
2519
    uchar* buf,
2520
2520
    bool has_hpk,
2521
2521
    uint pk_index,
2681
2681
    return pos - buf;
2682
2682
}
2683
2683
 
2684
 
uint32_t skip_key_in_desc(
 
2684
static uint32_t skip_key_in_desc(
2685
2685
    uchar* row_desc
2686
2686
    ) 
2687
2687
{
2717
2717
}
2718
2718
 
2719
2719
 
2720
 
uint32_t max_key_size_from_desc(
 
2720
static uint32_t max_key_size_from_desc(
2721
2721
    void* row_desc,
2722
2722
    uint32_t row_desc_size
2723
2723
    ) 
2802
2802
    return max_size;
2803
2803
}
2804
2804
 
2805
 
uint32_t pack_key_from_desc(
 
2805
static uint32_t pack_key_from_desc(
2806
2806
    uchar* buf,
2807
2807
    void* row_desc,
2808
2808
    uint32_t row_desc_size,
3140
3140
    return (uint32_t)(packed_key_pos - buf); // 
3141
3141
}
3142
3142
 
3143
 
bool fields_have_same_name(
3144
 
    Field* a,
3145
 
    Field* b
3146
 
    )
3147
 
{
 
3143
static bool fields_have_same_name(Field* a, Field* b) {
3148
3144
    return strcmp(a->field_name, b->field_name) == 0;
3149
3145
}
3150
3146
 
3151
 
bool fields_are_same_type(
3152
 
    Field* a, 
3153
 
    Field* b
3154
 
    )
3155
 
{
 
3147
static bool fields_are_same_type(Field* a, Field* b) {
3156
3148
    bool retval = true;
3157
3149
    enum_field_types a_mysql_type = a->real_type();
3158
3150
    enum_field_types b_mysql_type = b->real_type();
3209
3201
            goto cleanup;
3210
3202
        }
3211
3203
        break;
3212
 
    case MYSQL_TYPE_ENUM:
3213
 
    case MYSQL_TYPE_SET:
 
3204
    case MYSQL_TYPE_ENUM: {
 
3205
        Field_enum *a_enum = static_cast<Field_enum *>(a);
 
3206
        if (!a_enum->eq_def(b)) {
 
3207
            retval = false;
 
3208
            goto cleanup;
 
3209
        }
 
3210
        break;
 
3211
    }   
 
3212
    case MYSQL_TYPE_SET: {
 
3213
        Field_set *a_set = static_cast<Field_set *>(a);
 
3214
        if (!a_set->eq_def(b)) {
 
3215
            retval = false;
 
3216
            goto cleanup;
 
3217
        }
 
3218
        break;
 
3219
    }
3214
3220
    case MYSQL_TYPE_BIT:
3215
3221
        // length
3216
3222
        if (a->pack_length() != b->pack_length()) {
3224
3230
    case MYSQL_TYPE_NEWDATE:
3225
3231
    case MYSQL_TYPE_TIME:
3226
3232
    case MYSQL_TYPE_TIMESTAMP:
3227
 
#if 50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699
 
3233
#if (50600 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50699) || \
 
3234
    (50700 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 50799) || \
 
3235
    (100000 <= MYSQL_VERSION_ID && MYSQL_VERSION_ID <= 100099)
3228
3236
    case MYSQL_TYPE_DATETIME2:
3229
3237
    case MYSQL_TYPE_TIMESTAMP2:
3230
3238
    case MYSQL_TYPE_TIME2:
3313
3321
    return retval;
3314
3322
}
3315
3323
 
3316
 
 
3317
 
bool are_two_fields_same(
3318
 
    Field* a,
3319
 
    Field* b
3320
 
    )
3321
 
{
 
3324
static bool are_two_fields_same(Field* a, Field* b) {
3322
3325
    return fields_have_same_name(a, b) && fields_are_same_type(a, b);
3323
3326
}
3324
3327