Skip to content

Commit 479fb2a

Browse files
obdevob-robot
authored andcommitted
[CP]Protocol security vulnerabilities
1 parent a2b4aa3 commit 479fb2a

File tree

5 files changed

+73
-45
lines changed

5 files changed

+73
-45
lines changed

deps/oblib/src/rpc/obmysql/ob_mysql_util.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,30 @@ int ObMySQLUtil::get_length(const char *&pos, uint64_t &length)
110110
get_uint3(pos, s4);
111111
length = s4;
112112
} else if (sentinel == 254) {
113-
get_uint8(pos, length);
113+
if (lib::is_oracle_mode()) {
114+
get_uint8(pos, length);
115+
} else {
116+
/*
117+
In our client-server protocol all numbers bigger than 2^24
118+
stored as 8 bytes with uint8korr. Here we always know that
119+
parameter length is less than 2^4 so we don't look at the second
120+
4 bytes. But still we need to obey the protocol hence 9 in the
121+
assignment below.
122+
if (packet_left_len < 9) {
123+
*header_len = 0;
124+
return 0;
125+
}
126+
*header_len = 9;
127+
return static_cast<ulong>(uint4korr(packet + 1));
128+
129+
OceanBase length parsing compatible with mysql, so we don't look at the second
130+
4 bytes. But still we need to obey the protocol hence 9 in the
131+
assignment below.
132+
*/
133+
get_uint4(pos, s4);
134+
length = s4;
135+
pos += 4;
136+
}
114137
} else {
115138
// 255??? won't get here.
116139
pos--; // roll back

deps/oblib/src/rpc/obmysql/packet/ompk_handshake_response.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ int OMPKHandshakeResponse::decode()
6767

6868
// get username
6969
if (OB_SUCC(ret) && pos < end) {
70-
username_ = ObString::make_string(pos);
71-
pos += strlen(pos) + 1;
70+
int64_t len = strnlen(pos, end - pos);
71+
username_ = ObString(0, len, const_cast<char *>(pos));
72+
pos += len + 1;
7273
}
7374

7475
// get auth response
@@ -93,24 +94,27 @@ int OMPKHandshakeResponse::decode()
9394
pos += auth_response_len;
9495
} else {
9596
//string[NUL] auth-response
96-
auth_response_ = ObString::make_string(pos);
97-
pos += strlen(pos) + 1;
97+
int64_t len = strnlen(pos, end - pos);
98+
auth_response_ = ObString(0, len, const_cast<char *>(pos));
99+
pos += len + 1;
98100
}
99101
}
100102

101103
// get database name
102104
if (OB_SUCC(ret) && pos < end) {
103105
if (capability_.cap_flags_.OB_CLIENT_CONNECT_WITH_DB) {
104-
database_ = ObString::make_string(pos);
105-
pos += strlen(pos) + 1;
106+
int64_t len = strnlen(pos, end - pos);
107+
database_ = ObString(0, len, const_cast<char *>(pos));
108+
pos += len + 1;
106109
}
107110
}
108111

109112
// get auth plugin name
110113
if (OB_SUCC(ret) && pos < end) {
111114
if (capability_.cap_flags_.OB_CLIENT_PLUGIN_AUTH) {
112-
auth_plugin_name_ = ObString::make_string(pos);
113-
pos += strlen(pos) + 1;
115+
int64_t len = strnlen(pos, end - pos);
116+
auth_plugin_name_ = ObString(0, len, const_cast<char *>(pos));
117+
pos += len + 1;
114118
}
115119
}
116120

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
create table tt1(a int, b int, c int, primary key(a)) with column group (all columns, each column);
2-
create index idx_tt1 on tt1(b);
3-
create table tt2(d int, e int);
4-
alter table tt1 modify column c varchar(20);
5-
alter table tt1 drop column c;
6-
drop table tt1;
7-
drop table tt2;
1+
create table cg_tt1(a int, b int, c int, primary key(a)) with column group (all columns, each column);
2+
create index idx_cg_tt1 on cg_tt1(b);
3+
create table cg_tt2(d int, e int);
4+
alter table cg_tt1 modify column c varchar(20);
5+
alter table cg_tt1 drop column c;
6+
drop table cg_tt1;
7+
drop table cg_tt2;

tools/deploy/mysql_test/test_suite/column_store/t/basic_column_group_syntax.test

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,50 @@ connection sys_conn;
88
--disable_query_log
99
--disable_warnings
1010
set @@recyclebin = off;
11-
drop table if exists tt1;
12-
drop table if exists tt2;
11+
drop table if exists cg_tt1;
12+
drop table if exists cg_tt2;
1313
--enable_warnings
1414
--enable_query_log
1515

16-
create table tt1(a int, b int, c int, primary key(a)) with column group (all columns, each column);
17-
create index idx_tt1 on tt1(b);
18-
create table tt2(d int, e int);
19-
alter table tt1 modify column c varchar(20);
20-
alter table tt1 drop column c;
16+
create table cg_tt1(a int, b int, c int, primary key(a)) with column group (all columns, each column);
17+
create index idx_cg_tt1 on cg_tt1(b);
18+
create table cg_tt2(d int, e int);
19+
alter table cg_tt1 modify column c varchar(20);
20+
alter table cg_tt1 drop column c;
2121

22-
let $tt1_table_id= query_get_value(select table_id from __all_virtual_table where table_name='tt1', table_id, 1);
23-
let $tt2_table_id= query_get_value(select table_id from __all_virtual_table where table_name='tt2', table_id, 1);
22+
let $cg_tt1_table_id= query_get_value(select table_id from __all_virtual_table where table_name='cg_tt1', table_id, 1);
23+
let $cg_tt2_table_id= query_get_value(select table_id from __all_virtual_table where table_name='cg_tt2', table_id, 1);
2424

25-
## In tt1 table schema, there exists 4 column_group: __cg_default, __cg_all, __cg_a, __cg_b
26-
let $tt1_cg_cnt = query_get_value(select count(*) as cg_cnt from __all_column_group where table_id=$tt1_table_id, cg_cnt, 1);
27-
if ($tt1_cg_cnt != 5)
25+
## In cg_tt1 table schema, there exists 4 column_group: __cg_default, __cg_all, __cg_a, __cg_b
26+
let $cg_tt1_cg_cnt = query_get_value(select count(*) as cg_cnt from __all_column_group where table_id=$cg_tt1_table_id, cg_cnt, 1);
27+
if ($cg_tt1_cg_cnt != 5)
2828
{
29-
--echo unexpected column_group count of table tt1, real value is $tt1_cg_cnt
29+
--echo unexpected column_group count of table cg_tt1, real value is $cg_tt1_cg_cnt
3030
}
31-
## tt1 default_type column_group will have none column_id mapping, cuz it has all_type & each_type column_group
32-
let $tt1_default_cg_id = query_get_value(select column_group_id from __all_column_group where table_id=$tt1_table_id and column_group_name='__co_default', column_group_id, 1);
33-
let $tt1_column_id_cnt = query_get_value(select count(*) as mapping_cnt from __all_column_group_mapping where table_id=$tt1_table_id and column_group_id=$tt1_default_cg_id, mapping_cnt, 1);
34-
if ($tt1_column_id_cnt != 0)
31+
## cg_tt1 default_type column_group will have none column_id mapping, cuz it has all_type & each_type column_group
32+
let $cg_tt1_default_cg_id = query_get_value(select column_group_id from __all_column_group where table_id=$cg_tt1_table_id and column_group_name='__co_default', column_group_id, 1);
33+
let $cg_tt1_column_id_cnt = query_get_value(select count(*) as mapping_cnt from __all_column_group_mapping where table_id=$cg_tt1_table_id and column_group_id=$cg_tt1_default_cg_id, mapping_cnt, 1);
34+
if ($cg_tt1_column_id_cnt != 0)
3535
{
36-
--echo unexpected column_group mapping count of table tt1, real value is $tt1_column_id_cnt;
36+
--echo unexpected column_group mapping count of table cg_tt1, real value is $cg_tt1_column_id_cnt;
3737
}
3838

39-
## In tt2 table schema, there exists only 1 column_group: __co_default
40-
let $tt2_cg_cnt = query_get_value(select count(*) as cg_cnt from __all_column_group where table_id=$tt2_table_id, cg_cnt, 1);
41-
if ($tt2_cg_cnt != 1)
39+
## In cg_tt2 table schema, there exists only 1 column_group: __co_default
40+
let $cg_tt2_cg_cnt = query_get_value(select count(*) as cg_cnt from __all_column_group where table_id=$cg_tt2_table_id, cg_cnt, 1);
41+
if ($cg_tt2_cg_cnt != 1)
4242
{
43-
--echo unexpected column_group count of table tt2, real value is $tt2_cg_cnt
43+
--echo unexpected column_group count of table cg_tt2, real value is $cg_tt2_cg_cnt
4444
}
45-
## tt2 default_type column_group will have 3 column_id mapping, include d, e, pk_increment
46-
let $tt2_default_cg_id = query_get_value(select column_group_id from __all_column_group where table_id=$tt2_table_id and column_group_name='__co_default', column_group_id, 1);
47-
let $tt2_column_id_cnt = query_get_value(select count(*) as mapping_cnt from __all_column_group_mapping where table_id=$tt2_table_id and column_group_id=$tt2_default_cg_id, mapping_cnt, 1);
48-
if ($tt2_column_id_cnt != 3)
45+
## cg_tt2 default_type column_group will have 3 column_id mapping, include d, e, pk_increment
46+
let $cg_tt2_default_cg_id = query_get_value(select column_group_id from __all_column_group where table_id=$cg_tt2_table_id and column_group_name='__co_default', column_group_id, 1);
47+
let $cg_tt2_column_id_cnt = query_get_value(select count(*) as mapping_cnt from __all_column_group_mapping where table_id=$cg_tt2_table_id and column_group_id=$cg_tt2_default_cg_id, mapping_cnt, 1);
48+
if ($cg_tt2_column_id_cnt != 3)
4949
{
50-
--echo unexpected column_group mapping count of table tt2, real value is $tt2_column_id_cnt
50+
--echo unexpected column_group mapping count of table cg_tt2, real value is $cg_tt2_column_id_cnt
5151
}
5252

53-
drop table tt1;
54-
drop table tt2;
53+
drop table cg_tt1;
54+
drop table cg_tt2;
5555

5656
--disable_query_log
5757
set @@recyclebin = on;

tools/deploy/mysql_test/test_suite/merge_uncommitted/t/commit_after_minor_merge.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
set @@session.explicit_defaults_for_timestamp=off;
77
--enable_query_log
88

9+
--source mysql_test/include/wait_daily_merge.inc
910
connect (conn0,$OBMYSQL_MS0,admin,$OBMYSQL_PWD,oceanbase,$OBMYSQL_PORT);
1011

1112
let $__timeout_def__ = 60 * 1000 * 1000;

0 commit comments

Comments
 (0)