Skip to content

Commit 8f9a2b8

Browse files
authored
Fix a Panic in admin commands (#779)
We have a panic when we send SHOW or ;;;;;;;;;;;;;;;;; to admin database. This PR fixes these panics and adds a couple of tests
1 parent cbf4d58 commit 8f9a2b8

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/admin.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ where
5555

5656
let query_parts: Vec<&str> = query.trim_end_matches(';').split_whitespace().collect();
5757

58-
match query_parts[0].to_ascii_uppercase().as_str() {
58+
match query_parts
59+
.first()
60+
.unwrap_or(&"")
61+
.to_ascii_uppercase()
62+
.as_str()
63+
{
5964
"BAN" => {
6065
trace!("BAN");
6166
ban(stream, query_parts).await
@@ -84,7 +89,12 @@ where
8489
trace!("SHUTDOWN");
8590
shutdown(stream).await
8691
}
87-
"SHOW" => match query_parts[1].to_ascii_uppercase().as_str() {
92+
"SHOW" => match query_parts
93+
.get(1)
94+
.unwrap_or(&"")
95+
.to_ascii_uppercase()
96+
.as_str()
97+
{
8898
"HELP" => {
8999
trace!("SHOW HELP");
90100
show_help(stream).await

tests/ruby/admin_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@
9191
end
9292
end
9393

94+
[
95+
"SHOW ME THE MONEY",
96+
"SHOW ME THE WAY",
97+
"SHOW UP",
98+
"SHOWTIME",
99+
"HAMMER TIME",
100+
"SHOWN TO BE TRUE",
101+
"SHOW ",
102+
"SHOW ",
103+
"SHOW 1",
104+
";;;;;"
105+
].each do |cmd|
106+
describe "Bad command #{cmd}" do
107+
it "does not panic and responds with PG::SystemError" do
108+
admin_conn = PG::connect(processes.pgcat.admin_connection_string)
109+
expect { admin_conn.async_exec(cmd) }.to raise_error(PG::SystemError).with_message(/Unsupported/)
110+
admin_conn.close
111+
end
112+
end
113+
end
114+
94115
describe "PAUSE" do
95116
it "pauses all pools" do
96117
admin_conn = PG::connect(processes.pgcat.admin_connection_string)

0 commit comments

Comments
 (0)