Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Fix issue #10: Segfault in RDBSE_KEYDEF::get_primary_key_tuple
Browse files Browse the repository at this point in the history
RDBSE_KEYDEF::pk_part_no was allocated with the wrong number of elements.
  • Loading branch information
spetrunia authored and Jonah Cohen committed Dec 19, 2014
1 parent a517b59 commit 096314e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
21 changes: 21 additions & 0 deletions mysql-test/r/rocksdb.result
Original file line number Diff line number Diff line change
Expand Up @@ -1325,3 +1325,24 @@ select * from t1 where pk=3;
pk col1
3 123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-123456789ABCDEF-
drop table t0, t1;
#
# Fix issue #10: Segfault in RDBSE_KEYDEF::get_primary_key_tuple
#
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t1 (
id1 bigint(20) unsigned NOT NULL DEFAULT '0',
id2 bigint(20) unsigned NOT NULL DEFAULT '0',
link_type bigint(20) unsigned NOT NULL DEFAULT '0',
visibility tinyint(3) NOT NULL DEFAULT '0',
data varchar(255) NOT NULL DEFAULT '',
time bigint(20) unsigned NOT NULL DEFAULT '0',
version int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (link_type,id1,id2)
) engine=rocksdb;
insert into t1 select a,a,a,1,a,a,a from t0;
alter table t1 add index id1_type (id1,link_type,visibility,time,version,data);
select * from t1 where id1 = 3;
id1 id2 link_type visibility data time version
3 3 3 1 3 3 3
drop table t0,t1;
25 changes: 25 additions & 0 deletions mysql-test/t/rocksdb.test
Original file line number Diff line number Diff line change
Expand Up @@ -1165,3 +1165,28 @@ create table t1 (
insert into t1 select a, repeat('123456789ABCDEF-', 15) from t0;
select * from t1 where pk=3;
drop table t0, t1;

--echo #
--echo # Fix issue #10: Segfault in RDBSE_KEYDEF::get_primary_key_tuple
--echo #
create table t0 (a int);
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

CREATE TABLE t1 (
id1 bigint(20) unsigned NOT NULL DEFAULT '0',
id2 bigint(20) unsigned NOT NULL DEFAULT '0',
link_type bigint(20) unsigned NOT NULL DEFAULT '0',
visibility tinyint(3) NOT NULL DEFAULT '0',
data varchar(255) NOT NULL DEFAULT '',
time bigint(20) unsigned NOT NULL DEFAULT '0',
version int(11) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (link_type,id1,id2)
) engine=rocksdb;

insert into t1 select a,a,a,1,a,a,a from t0;

alter table t1 add index id1_type (id1,link_type,visibility,time,version,data);
select * from t1 where id1 = 3;

drop table t0,t1;

8 changes: 6 additions & 2 deletions storage/rocksdb/rdb_datadic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ void RDBSE_KEYDEF::setup(TABLE *tbl)
if (keyno != tbl->s->primary_key)
{
n_pk_key_parts= pk_info->actual_key_parts;
pk_part_no= (uint*)my_malloc(sizeof(uint)*n_pk_key_parts, MYF(0));
}
else
{
pk_info= NULL;
pk_part_no= NULL;
n_pk_key_parts= 0;
}

// "unique" secondary keys support:
Expand All @@ -93,6 +92,11 @@ void RDBSE_KEYDEF::setup(TABLE *tbl)
unique_secondary_index= true;
}

if (keyno != tbl->s->primary_key)
pk_part_no= (uint*)my_malloc(sizeof(uint)*m_key_parts, MYF(0));
else
pk_part_no= NULL;

size_t size= sizeof(Field_pack_info) * m_key_parts;
pack_info= (Field_pack_info*)my_malloc(size, MYF(0));

Expand Down

0 comments on commit 096314e

Please sign in to comment.