Skip to content

Commit 6da002f

Browse files
committed
fix(pgwire): guard against out-of-bounds access in DDL command parsers
Replace direct index access with bounds-checked alternatives in the auth user DDL handler, and add early-return validation in GRANT/REVOKE ROLE handlers to return a well-formed syntax error instead of panicking when the command has too few parts.
1 parent 7097421 commit 6da002f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

nodedb/src/control/server/pgwire/ddl/auth_user_ddl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn handle_auth_user(
3232
));
3333
}
3434

35-
let upper0 = parts[0].to_uppercase();
35+
let upper0 = parts.first().map(|s| s.to_uppercase()).unwrap_or_default();
3636
match upper0.as_str() {
3737
"DEACTIVATE" => deactivate_auth_user(state, identity, parts),
3838
"ALTER" => alter_auth_user_status(state, identity, parts),

nodedb/src/control/server/pgwire/ddl/grant/role.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ pub fn grant_role(
5757
) -> PgWireResult<Vec<Response>> {
5858
require_admin(identity, "grant roles")?;
5959

60+
if parts.len() < 5 {
61+
return Err(sqlstate_error(
62+
"42601",
63+
"syntax: GRANT ROLE <role> TO <user>",
64+
));
65+
}
66+
6067
let role = parse_role(parts[2]);
6168

6269
if matches!(role, Role::Superuser) && !identity.is_superuser {
@@ -94,6 +101,13 @@ pub fn revoke_role(
94101
) -> PgWireResult<Vec<Response>> {
95102
require_admin(identity, "revoke roles")?;
96103

104+
if parts.len() < 5 {
105+
return Err(sqlstate_error(
106+
"42601",
107+
"syntax: REVOKE ROLE <role> FROM <user>",
108+
));
109+
}
110+
97111
let role = parse_role(parts[2]);
98112

99113
if !parts[3].eq_ignore_ascii_case("FROM") {

0 commit comments

Comments
 (0)