Skip to content

Commit 03f00cd

Browse files
Fix panic in SET AUTHORIZATION parsing when scope modifier is missing (apache#2201)
1 parent d526819 commit 03f00cd

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/parser/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14546,14 +14546,23 @@ impl<'a> Parser<'a> {
1454614546
}
1454714547
.into());
1454814548
} else if self.parse_keyword(Keyword::AUTHORIZATION) {
14549+
let scope = match scope {
14550+
Some(s) => s,
14551+
None => {
14552+
return self.expected_at(
14553+
"SESSION, LOCAL, or other scope modifier before AUTHORIZATION",
14554+
self.get_current_index(),
14555+
)
14556+
}
14557+
};
1454914558
let auth_value = if self.parse_keyword(Keyword::DEFAULT) {
1455014559
SetSessionAuthorizationParamKind::Default
1455114560
} else {
1455214561
let value = self.parse_identifier()?;
1455314562
SetSessionAuthorizationParamKind::User(value)
1455414563
};
1455514564
return Ok(Set::SetSessionAuthorization(SetSessionAuthorizationParam {
14556-
scope: scope.expect("SET ... AUTHORIZATION must have a scope"),
14565+
scope,
1455714566
kind: auth_value,
1455814567
})
1455914568
.into());

tests/sqlparser_common.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18333,6 +18333,16 @@ fn test_parse_set_session_authorization() {
1833318333
);
1833418334
}
1833518335

18336+
#[test]
18337+
fn test_set_authorization_without_scope_errors() {
18338+
// This should return a parser error, not panic.
18339+
let res = parse_sql_statements("SET AUTHORIZATION TIME TIME");
18340+
assert!(
18341+
res.is_err(),
18342+
"SET AUTHORIZATION without a scope modifier (e.g. SESSION) should error"
18343+
);
18344+
}
18345+
1833618346
#[test]
1833718347
fn parse_select_parenthesized_wildcard() {
1833818348
// Test SELECT DISTINCT(*) which uses a parenthesized wildcard

0 commit comments

Comments
 (0)