From 09eb50a83e3f5f9fe1a44782c7685046a344042b Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Tue, 21 Nov 2023 13:55:07 +0500 Subject: [PATCH 1/2] Remove any trailing spaces and semicolons from the SET statement --- lib/MySQL_Session.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index d2ac2998ac..99afae7fbf 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -6032,6 +6032,8 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C string nq=string((char *)CurrentQuery.QueryPointer,CurrentQuery.QueryLength); 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); /* // we do not threat SET SQL_LOG_BIN as a special case if (match_regexes && match_regexes[0]->match(dig)) { From 786be5f89b67433f807950c857cf69d4d1f111d9 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 27 Nov 2023 12:00:02 +0500 Subject: [PATCH 2/2] Updated TAP test * Added functionality for generating strings composed of randomly selected characters from ';' and ' ', with lengths ranging from 1 to 8. These generated strings are intended to be appended to executed queries. --- test/tap/tests/set_testing-240-t.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/tap/tests/set_testing-240-t.cpp b/test/tap/tests/set_testing-240-t.cpp index 0576bc4b81..2cd9cff09d 100644 --- a/test/tap/tests/set_testing-240-t.cpp +++ b/test/tap/tests/set_testing-240-t.cpp @@ -82,6 +82,29 @@ class var_counter { } }; +// Generate string containing randomly chosen characters between +// ';' and ' ', with length between 1 and 8 +std::string generate_random_noise() { + // Seed the random number generator with the current time + std::srand(static_cast(std::time(nullptr))); + + static const char characters[] = { ';', ' ' }; + static const int numCharacters = sizeof(characters) / sizeof(char); + + // max lengh of string is 8 + const int length = std::rand() % 8 + 1; + + std::string randomString; + randomString.reserve(length); + + for (int i = 0; i < length; ++i) { + char randomChar = characters[std::rand() % numCharacters]; + randomString.push_back(randomChar); + } + + return randomString; +} + //std::unordered_map unknown_var_counters; std::unordered_map vars_counters; @@ -160,6 +183,7 @@ void * my_conn_thread(void *arg) { diag("Thread_id: %lu, random number: %d . Query/ies: %s", mysql->thread_id, r2, testCases[r2].command.c_str()); std::vector commands = split(testCases[r2].command.c_str(), ';'); for (auto c : commands) { + c += generate_random_noise(); if (mysql_query(mysql, c.c_str())) { if (silent==0) { fprintf(stderr,"ERROR while running -- \"%s\" : (%d) %s\n", c.c_str(), mysql_errno(mysql), mysql_error(mysql));