diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 815cd65fa9..e4ba12f440 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -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)) { diff --git a/lib/set_parser.cpp b/lib/set_parser.cpp index 983897a70e..2d28da923a 100644 --- a/lib/set_parser.cpp +++ b/lib/set_parser.cpp @@ -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(""); @@ -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(""); @@ -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) {