Skip to content

Commit

Permalink
Add check before trying to remove trailing spaces or semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
renecannao committed Aug 29, 2024
1 parent 645963a commit c76dda6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6479,7 +6479,10 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
RE2::GlobalReplace(&nq,(char *)"^/\\*!\\d\\d\\d\\d\\d SET(.*)\\*/",(char *)"SET\\1");
RE2::GlobalReplace(&nq,(char *)"(?U)/\\*.*\\*/",(char *)"");
// remove trailing space and semicolon if present. See issue#4380
nq.erase(nq.find_last_not_of(" ;") + 1);
size_t pos = nq.find_last_not_of(" ;");
if (pos != nq.npos) {
nq.erase(pos + 1); // remove trailing spaces and semicolumns
}
/*
// we do not threat SET SQL_LOG_BIN as a special case
if (match_regexes && match_regexes[0]->match(dig)) {
Expand Down
15 changes: 12 additions & 3 deletions lib/set_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ VALGRIND_ENABLE_ERROR_REPORTING;
} else if (strcasecmp("transaction_read_only", value4.c_str()) == 0) {
value4 = "tx_read_only";
}
value5.erase(value5.find_last_not_of(" \n\r\t,")+1);
size_t pos = value5.find_last_not_of(" \n\r\t,");
if (pos != value5.npos) {
value5.erase(pos+1);
}
key = value4;
if (value5 == "''" || value5 == "\"\"") {
op.push_back("");
Expand Down Expand Up @@ -405,7 +408,10 @@ VALGRIND_ENABLE_ERROR_REPORTING;
} else if (strcasecmp("transaction_read_only", value4.c_str()) == 0) {
value4 = "tx_read_only";
}
value5.erase(value5.find_last_not_of(" \n\r\t,")+1);
size_t pos = value5.find_last_not_of(" \n\r\t,");
if (pos != value5.npos) {
value5.erase(pos+1);
}
key = value4;
if (value5 == "''" || value5 == "\"\"") {
op.push_back("");
Expand Down Expand Up @@ -519,7 +525,10 @@ std::string SetParser::parse_USE_query(std::string& errmsg) {
opt2.set_longest_match(false);

std::string dbname = remove_comments(query);
dbname.erase(dbname.find_last_not_of(" ;") + 1); // remove trailing spaces and semicolumns
size_t pos = dbname.find_last_not_of(" ;");
if (pos != dbname.npos) {
dbname.erase(pos + 1); // remove trailing spaces and semicolumns
}
re2::RE2 re0("^\\s*", opt2);
re2::RE2::Replace(&dbname, re0, "");
if (dbname.size() >= 4) {
Expand Down

0 comments on commit c76dda6

Please sign in to comment.