From 43cfa5eab5b49315edac57a5e960fd7a6ea5341c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 4 May 2018 10:50:47 +0300 Subject: [PATCH 1/2] Fix TSV output in MaxCtrl The output in --tsv mode could break the TSV format if newlines or tabs were included in the data. --- maxctrl/lib/common.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/maxctrl/lib/common.js b/maxctrl/lib/common.js index cab6d9057..d659c1d28 100644 --- a/maxctrl/lib/common.js +++ b/maxctrl/lib/common.js @@ -19,6 +19,26 @@ var os = require('os') var fs = require('fs') var readlineSync = require('readline-sync') +function normalizeWhitespace(table) { + table.forEach((v) => { + if (Array.isArray(v)) { + // `table` is an array of arrays + v.forEach((k) => { + if (typeof(v[k]) == 'string') { + v[k] = v[k].replace( /\s+/g, ' ') + } + }) + } else if (!Array.isArray(v) && v instanceof Object) { + // `table` is an array of objects + Object.keys(v).forEach((k) => { + if (typeof(v[k]) == 'string') { + v[k] = v[k].replace( /\s+/g, ' ') + } + }) + } + }) +} + module.exports = function() { this._ = require('lodash-getpath') @@ -101,7 +121,15 @@ module.exports = function() { } this.tableToString = function(table) { + + if (this.argv.tsv) + { + // Convert whitespace into spaces to prevent breaking the TSV format + normalizeWhitespace(table) + } + str = table.toString() + if (this.argv.tsv) { // Based on the regex found in: https://github.com/jonschlinkert/strip-color str = str.replace( /\x1B\[[(?);]{0,2}(;?\d)*./g, '') From 689c02d3019dcb85d07999605d480e1dd43bceb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 4 May 2018 12:42:46 +0300 Subject: [PATCH 2/2] Send error on reauthentication failure When the reauthentication of a client fails, the correct error should be sent. --- .../modules/protocol/MySQL/mariadbclient/mysql_client.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc index b813d9911..6751ee1ff 100644 --- a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc +++ b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc @@ -1481,7 +1481,14 @@ static bool reauthenticate_client(MXS_SESSION* session, GWBUF* packetbuf) proto->scramble, sizeof(proto->scramble), client_sha1, sizeof(client_sha1)); - rval = rc == MXS_AUTH_SUCCEEDED; + if (!(rval = rc == MXS_AUTH_SUCCEEDED)) + { + /** + * First packet is COM_CHANGE_USER, the second is AuthSwitchRequest, + * third is the response and the fourth is the following error. + */ + mysql_client_auth_error_handling(session->client_dcb, rc, 3); + } } return rval;