mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-07 13:52:59 +00:00
fix: panic when received invalid query string (#5366)
Signed-off-by: Ruihang Xia <waynestxia@gmail.com>
This commit is contained in:
@@ -273,8 +273,11 @@ pub(crate) fn check(
|
||||
) -> Option<Output> {
|
||||
// INSERT don't need MySQL federated check. We assume the query doesn't contain
|
||||
// federated or driver setup command if it starts with a 'INSERT' statement.
|
||||
if query.len() > 6 && query[..6].eq_ignore_ascii_case("INSERT") {
|
||||
return None;
|
||||
let the_6th_index = query.char_indices().nth(6).map(|(i, _)| i);
|
||||
if let Some(index) = the_6th_index {
|
||||
if query[..index].eq_ignore_ascii_case("INSERT") {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
// First to check the query is like "select @@variables".
|
||||
@@ -295,6 +298,15 @@ mod test {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_check_abnormal() {
|
||||
let session = Arc::new(Session::new(None, Channel::Mysql, Default::default()));
|
||||
let query = "🫣一点不正常的东西🫣";
|
||||
let output = check(query, QueryContext::arc(), session.clone());
|
||||
|
||||
assert!(output.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_check() {
|
||||
let session = Arc::new(Session::new(None, Channel::Mysql, Default::default()));
|
||||
|
||||
Reference in New Issue
Block a user