From 6aed6becece4145bf19c3b485d3eaff0241532b3 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 23 Jan 2023 16:40:00 +0100 Subject: [PATCH] virNetSSHSessionAuthAddPasswordAuth: Don't access unlocked 'sess' MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 'sess->authPath' is modified before locking the 'sess' object. Additionally on failure of 'virAuthGetConfigFilePathURI' 'sess' would be unlocked even when it was not yet locked. Fixes: 273745b43122a77adf8c73b2e0a852ac42387349 Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/rpc/virnetsshsession.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 8584a961d6..73e65d9371 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -970,15 +970,17 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSession *sess, { virNetSSHAuthMethod *auth; + virObjectLock(sess); + if (uri) { VIR_FREE(sess->authPath); - if (virAuthGetConfigFilePathURI(uri, &sess->authPath) < 0) - goto error; + if (virAuthGetConfigFilePathURI(uri, &sess->authPath) < 0) { + virObjectUnlock(sess); + return -1; + } } - virObjectLock(sess); - if (!(auth = virNetSSHSessionAuthMethodNew(sess))) goto error; -- 2.47.2