From 355f34669df9372ccfbd25d939018896d09d10ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 16 Nov 2018 12:39:09 +0200 Subject: [PATCH] Sanitize log_matches input Given that the pattern is given as an argument quoted with single quotes, embedded single quotes are a problem. Given that most cases that they are used for is as parts of natural words like can't or won't. By replacing the single quotes with wildcard characters, we make sure the input is formatted correctly while still matching with relatively high accuracy. --- maxscale-system-test/testconnections.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index e020f76b1..edfa6a081 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -1233,7 +1233,18 @@ int TestConnections::start_mm(int m) bool TestConnections::log_matches(int m, const char* pattern) { - return maxscales->ssh_node_f(m, true, "grep '%s' /var/log/maxscale/maxscale*.log", pattern) == 0; + + // Replace single quotes with wildcard characters, should solve most problems + std::string p = pattern; + for (auto& a : p) + { + if (a == '\'') + { + a = '.'; + } + } + + return maxscales->ssh_node_f(m, true, "grep '%s' /var/log/maxscale/maxscale*.log", p.c_str()) == 0; } void TestConnections::log_includes(int m, const char* pattern)