Skip to content

Commit

Permalink
fix: panic when received invalid query string (#5366)
Browse files Browse the repository at this point in the history
Signed-off-by: Ruihang Xia <[email protected]>
  • Loading branch information
waynexia authored Jan 16, 2025
1 parent 86bd541 commit a598008
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/servers/src/mysql/federated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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()));
Expand Down

0 comments on commit a598008

Please sign in to comment.