yoshinorim / mha4mysql-node

Development tree of Master High Availability Manager and tools for MySQL (MHA), Node (MySQL Server) part
http://code.google.com/p/mysql-master-ha/
GNU General Public License v2.0
398 stars 198 forks source link

escape_for_shell double-escapes #24

Open hholzgra opened 7 years ago

hholzgra commented 7 years ago

escape_for_shell() function escapes characters with "special" meaning to the shell, like \ or #, and also puts the result string into single quotes. Within single quotes these special characters do not have a special meaning though, especially a \ inside single quotes is just a regular character, eg:

$ echo \\
\

$ echo '\\'
\\

So for example a password containing a #, like secr#t, becomes 'secr\#t', while the correctly shell-escaped forms would be either secr\#t (with backslash but without single qoutes) or 'secr#t' (in single quotes, but without backslash). This then breaks invocation of external scripts like master_ip_failover and master_ip_online_change

The fix for this would be simple: do not put the already backslash-escaped string into extra single quotes:

diff --git a/lib/MHA/NodeUtil.pm b/lib/MHA/NodeUtil.pm
index c0bdba5..ed8b407 100644
--- a/lib/MHA/NodeUtil.pm
+++ b/lib/MHA/NodeUtil.pm
@@ -253,7 +253,7 @@ sub escape_for_shell {
     }
     $ret .= "$x";
   }
-  $ret = "'" . $ret . "'";
+#  $ret = "'" . $ret . "'";
   return $ret;
 }