Skip to content

Commit 98c3da7

Browse files
authored
fix(query): user/role name not support \b and \f (#17530)
1 parent 3d84543 commit 98c3da7

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

src/query/sql/src/planner/binder/binder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl<'a> Binder {
408408
} => {
409409
if illegal_ident_name(role_name) {
410410
return Err(ErrorCode::IllegalRole(
411-
format!("Illegal Role Name: Illegal role name [{}], not support username contain ' or \"", role_name),
411+
format!("Illegal Role Name: Illegal role name [{}], not support username contain ' or \" or \\b or \\f", role_name),
412412
));
413413
}
414414
Plan::CreateRole(Box::new(CreateRolePlan {

src/query/sql/src/planner/binder/ddl/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ impl Binder {
265265
} = stmt;
266266
if illegal_ident_name(&user.username) {
267267
return Err(ErrorCode::IllegalUser(format!(
268-
"Illegal Username: Illegal user name [{}], not support username contain ' or \"",
268+
"Illegal Username: Illegal user name [{}], not support username contain ' or \" \\b or \\f",
269269
user.username
270270
)));
271271
}

src/query/sql/src/planner/binder/util.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ use crate::NameResolutionSuggest;
3333
/// Ident name can not contain ' or "
3434
/// Forbidden ' or " in UserName and RoleName, to prevent Meta injection problem
3535
pub fn illegal_ident_name(ident_name: &str) -> bool {
36-
ident_name.chars().any(|c| c == '\'' || c == '\"')
36+
ident_name
37+
.chars()
38+
.any(|c| c == '\'' || c == '\"' || c == '\u{000C}' || c == '\u{0008}')
3739
}
3840

3941
impl Binder {

tests/sqllogictests/suites/base/05_ddl/05_0004_ddl_create_user.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,15 @@ create user `a"a` identified by '123'
9090

9191
statement error 2218
9292
create user `a'a` identified by '123'
93+
94+
statement error 2218
95+
CREATE user 'a\b' identified by '123'
96+
97+
statement error 2218
98+
CREATE user 'a\f' identified by '123'
99+
100+
statement ok
101+
drop user if exists 'a\b';
102+
103+
statement ok
104+
drop user if exists 'a\f';

tests/sqllogictests/suites/base/05_ddl/05_0014_ddl_create_role.test

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ CREATE ROLE `test-a`
77
statement error 2216
88
CREATE ROLE `test-a`
99

10+
statement error 2217
11+
CREATE ROLE 'a\b'
12+
13+
statement error 2217
14+
CREATE ROLE 'a\f'
15+
16+
statement ok
17+
drop role if exists 'a\b';
18+
19+
statement ok
20+
drop role if exists 'a\f';
21+
1022
statement ok
1123
CREATE ROLE IF NOT EXISTS `test-a`
1224

@@ -32,7 +44,7 @@ statement error 2217
3244
create role 'public'
3345

3446
statement error 2217
35-
create role `a"a`
47+
create role 'a"a'
3648

3749
statement error 2217
38-
create role `a'a`
50+
create role "a'a"

0 commit comments

Comments
 (0)