From c4adb99f12541d6ef2c5f0bc15ce87aa168517e4 Mon Sep 17 00:00:00 2001 From: rusher Date: Thu, 25 May 2023 15:45:35 +0200 Subject: [PATCH] [CONJS-256] changeUser can lead to error when using multi-authentication and pipelining --- lib/cmd/change-user.js | 10 +++++----- lib/connection.js | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/cmd/change-user.js b/lib/cmd/change-user.js index 0efa392e..d1d09c0e 100644 --- a/lib/cmd/change-user.js +++ b/lib/cmd/change-user.js @@ -7,15 +7,15 @@ const Capabilities = require('../const/capabilities'); const Ed25519PasswordAuth = require('./handshake/auth/ed25519-password-auth'); const NativePasswordAuth = require('./handshake/auth/native-password-auth'); const Collations = require('../const/collations'); -const Handshake = require('./handshake/authentication'); +const Authentication = require('./handshake/authentication'); /** * send a COM_CHANGE_USER: resets the connection and re-authenticates with the given credentials * see https://mariadb.com/kb/en/library/com_change_user/ */ -class ChangeUser extends Handshake { - constructor(cmdParam, connOpts, resolve, reject, addCommand) { - super(cmdParam, resolve, reject, () => {}, addCommand); +class ChangeUser extends Authentication { + constructor(cmdParam, connOpts, resolve, reject, getSocket) { + super(cmdParam, resolve, reject, () => {}, getSocket); this.configAssign(connOpts, cmdParam.opts); } @@ -104,7 +104,7 @@ class ChangeUser extends Handshake { } out.flush(); - this.onPacketReceive = this.handshakeResult; + this.plugin.onPacketReceive = this.handshakeResult.bind(this); } /** diff --git a/lib/connection.js b/lib/connection.js index 048faf6f..5738e70b 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -1239,17 +1239,18 @@ class Connection extends EventEmitter { reject(err); return; } - + this.addCommand = this.addCommandEnable; this.addCommand( new ChangeUser( cmdParam, this.opts, (res) => { + if (this.opts.pipelining) this.addCommand = this.addCommandEnablePipeline; if (cmdParam.opts && cmdParam.opts.collation) this.opts.collation = cmdParam.opts.collation; resolve(res); }, this.authFailHandler.bind(this, reject), - this.addCommand.bind(this) + this.getSocket.bind(this) ) ); }