From nobody Sat May 18 20:37:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674490147; cv=none; d=zohomail.com; s=zohoarc; b=H/xBCfyGt9pluGjNGKUgVqdN/IYorS047hKBX0A3jA1mLJIBJx7mNtDP1DUFcITbndrg30xP9hKZur+HqUMpAqIX9Xz45XZ3EPkpJ71fKaJsC9vC1TySPCF0eatHTqE6IsZ/MMGA/AcnrvZXG4pzUcHsOxhXB18YXEy+V6zeEsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674490147; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QLmxDr3qhgPE75DFI48UVnB1n7Cz0QDpgehFMvjRoNI=; b=Nu7FrGkJCgRPsWYjHC+T5L2sHNcpwjb+4NznXtnaK2J66lVNQZPqr8JZjY1sY6FKfLs6O5UqSBGV5QEUniG3tmYZuoNcdtm6x4d+1AoR41oxYBuWIlqmrKvVTUwCU9JPYJ+AS6vutD//ewPb5958thoSrXC1o7XG6b9efV5piv8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1674490147553867.8851032454331; Mon, 23 Jan 2023 08:09:07 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-232-VfZOwtoBNgumnHg_BQOMGQ-1; Mon, 23 Jan 2023 11:09:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 552613C0CD50; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 425DA40C1141; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3304D194658D; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id CA65A19465B5 for ; Mon, 23 Jan 2023 16:08:58 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id B01CA40C2005; Mon, 23 Jan 2023 16:08:58 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3C1440C2004 for ; Mon, 23 Jan 2023 16:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674490146; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QLmxDr3qhgPE75DFI48UVnB1n7Cz0QDpgehFMvjRoNI=; b=SvYp4YgKZmyVfOn06mh/6sOWp6ikMegph77iuVQJMDuYBf+C2jAzYgN+7U+5KWkTKzxnoM YeWf2/ByRr1aHZHcjlzjKNNH0DR694EBH6CTyG1eiXDz5RAeJmfXwgPG973n3/MF/sZQKD wDpk0gAguR38bRSj0aLz9Mqf8BoQvrA= X-MC-Unique: VfZOwtoBNgumnHg_BQOMGQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] util: authconfig: Don't check return value of 'g_key_file_new()' Date: Mon, 23 Jan 2023 17:08:51 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674490148662100001 Content-Type: text/plain; charset="utf-8" The function can't fail so it's pointless to check its return value. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virauthconfig.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/util/virauthconfig.c b/src/util/virauthconfig.c index 0363a1bef9..818df7a252 100644 --- a/src/util/virauthconfig.c +++ b/src/util/virauthconfig.c @@ -41,9 +41,7 @@ virAuthConfigNew(const char *path) g_autoptr(virAuthConfig) auth =3D g_new0(virAuthConfig, 1); auth->path =3D g_strdup(path); - - if (!(auth->keyfile =3D g_key_file_new())) - return NULL; + auth->keyfile =3D g_key_file_new(); if (!g_key_file_load_from_file(auth->keyfile, path, 0, NULL)) return NULL; @@ -60,9 +58,7 @@ virAuthConfigNewData(const char *path, g_autoptr(virAuthConfig) auth =3D g_new0(virAuthConfig, 1); auth->path =3D g_strdup(path); - - if (!(auth->keyfile =3D g_key_file_new())) - return NULL; + auth->keyfile =3D g_key_file_new(); if (!g_key_file_load_from_data(auth->keyfile, data, len, 0, NULL)) return NULL; --=20 2.38.1 From nobody Sat May 18 20:37:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674490150; cv=none; d=zohomail.com; s=zohoarc; b=nHZ2y0F2Kc3VFFEli67RpvSCMNYd7kfxypLM7cPlPaQejcUgmU/69R5mu0Dv9ze2Uae3m7AYxN/FFzJyIk7uSSlhZqS131PgJmWYUbsn6gPc+S6pmH6BGlLbbbTxCappzfuSN5vEU1zHZLnNznpIRphGtvI1L1GOdQkuseC6UFw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674490150; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5wHCmOWr85bBEULuKnAx6dAIkFANkOESCN2R0E5oom0=; b=MDcu5LXxcTK4Mg0nimwDtx+W4cfodIYncfX39FhDRQh+Q9B7QAanwXKCWrQwbc+x7HoC06HI2f6nMF8b5HIuQu6j2aj+9Vk7+QkZmEoX+z0K+gtKSeiSO37SJS5gA5rUx/DEEevuAeYJFznPwkksWR7R+nhZy6yURTBNFCTFVQ8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 167449015004517.226490482496843; Mon, 23 Jan 2023 08:09:10 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-75-PlG-LW1_Pq2ieSGoKjBUjQ-1; Mon, 23 Jan 2023 11:09:06 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3C053C0D866; Mon, 23 Jan 2023 16:09:02 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id B196AC15BA0; Mon, 23 Jan 2023 16:09:02 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8413B194658C; Mon, 23 Jan 2023 16:09:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 2DAD01946589 for ; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 068A540C2006; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B06B40C2004 for ; Mon, 23 Jan 2023 16:08:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674490148; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5wHCmOWr85bBEULuKnAx6dAIkFANkOESCN2R0E5oom0=; b=BbBDTgvISbj89IIJAu+rZqNVEFaC/kNK719wF4S2E5Wk8aL5gB8IKpX7u+t74KFRbV1qyX uCZbSB7GN0rVMQQXltQND4SdGduXYJaiBf42rvw562KBpiA/i2IYhWwson0rKzxGg4zRUh UYmhwbuBO+CJN0qInZBnHZjC2H+d0As= X-MC-Unique: PlG-LW1_Pq2ieSGoKjBUjQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] virNetSSHSessionAuthAddPasswordAuth: Don't access unlocked 'sess' Date: Mon, 23 Jan 2023 17:08:52 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674490150655100003 Content-Type: text/plain; charset="utf-8" '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=C3=A1n 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 =3D virNetSSHSessionAuthMethodNew(sess))) goto error; --=20 2.38.1 From nobody Sat May 18 20:37:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674490156; cv=none; d=zohomail.com; s=zohoarc; b=NcAJVFtAMh2TYjRTro9Q1hND0s9BjU9OgWwKGLix7EJtOkhlsKbyLENlfMoQ2tylhXuBRiZaxqlHVFBRyqT2GHFuxB8bEu7LZUS88ZODVFOPuQfhT+t9g2P8PRixDeiG4Jwi4QFLuK+MsD/8v+YYW36323GFe72BcuWV4W100JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674490156; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zR1M+ienC2pVXW8+/L7ALx2rSS7Lon8oTIkWqw3bqOU=; b=N5Hr/FYSTcuSVs1S962qLJoxBdRfLYxDlEQoM2B/SPnMFLCyM5ofkGo8yAzZTID8BoahGMFzKBoLgtp7KgLbS6uZkUUOEe/kjcs88HNMEUVMFxl2bH0qhf2PghapbE6KS0RVMh0+bBEAVJcrHnZjST5dPjzxl4y2LGXudIgfsGw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1674490156014962.7933236130398; Mon, 23 Jan 2023 08:09:16 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-659-DbgtSBa0MFidYtAoYhcIUw-1; Mon, 23 Jan 2023 11:09:07 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0231E1C068E1; Mon, 23 Jan 2023 16:09:05 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E31CC1121339; Mon, 23 Jan 2023 16:09:04 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C226A194658C; Mon, 23 Jan 2023 16:09:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id DF2931946589 for ; Mon, 23 Jan 2023 16:09:02 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id D092940C2005; Mon, 23 Jan 2023 16:09:02 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 83BF640C2006 for ; Mon, 23 Jan 2023 16:09:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674490154; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=zR1M+ienC2pVXW8+/L7ALx2rSS7Lon8oTIkWqw3bqOU=; b=RaQzeoGsle7NEAzTR8CuQc8f1QFZpGa7rSywHW4y60Xs7mQK6T8gjJSll9Mz5WPEM4Ocmg mhTSbqUa4fBGrLNLUMZcRWFnZtR3ZRXvIBpcLR+YQ1XaX6cn67azntcF1jJ0odhsgOe9R5 WCCvd0bbzAaNuw9bFLN3PsJLTZQ+MhE= X-MC-Unique: DbgtSBa0MFidYtAoYhcIUw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] virnetsshsession: Don't check return value of 'virNetSSHSessionAuthMethodNew' Date: Mon, 23 Jan 2023 17:08:53 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674490156770100002 Content-Type: text/plain; charset="utf-8" The function can't return NULL to the callers so it doesn't make sense to check it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetsshsession.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 73e65d9371..a3dd60f5a3 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -981,17 +981,11 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSession = *sess, } } - if (!(auth =3D virNetSSHSessionAuthMethodNew(sess))) - goto error; - + auth =3D virNetSSHSessionAuthMethodNew(sess); auth->method =3D VIR_NET_SSH_AUTH_PASSWORD; virObjectUnlock(sess); return 0; - - error: - virObjectUnlock(sess); - return -1; } int @@ -1001,17 +995,11 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSession *s= ess) virObjectLock(sess); - if (!(auth =3D virNetSSHSessionAuthMethodNew(sess))) - goto error; - + auth =3D virNetSSHSessionAuthMethodNew(sess); auth->method =3D VIR_NET_SSH_AUTH_AGENT; virObjectUnlock(sess); return 0; - - error: - virObjectUnlock(sess); - return -1; } int @@ -1028,11 +1016,7 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSession = *sess, virObjectLock(sess); - if (!(auth =3D virNetSSHSessionAuthMethodNew(sess))) { - virObjectUnlock(sess); - return -1; - } - + auth =3D virNetSSHSessionAuthMethodNew(sess); auth->filename =3D g_strdup(keyfile); auth->method =3D VIR_NET_SSH_AUTH_PRIVKEY; @@ -1048,19 +1032,12 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessio= n *sess, virObjectLock(sess); - if (!(auth =3D virNetSSHSessionAuthMethodNew(sess))) - goto error; - + auth =3D virNetSSHSessionAuthMethodNew(sess); auth->tries =3D tries; auth->method =3D VIR_NET_SSH_AUTH_KEYBOARD_INTERACTIVE; virObjectUnlock(sess); return 0; - - error: - virObjectUnlock(sess); - return -1; - } void --=20 2.38.1 From nobody Sat May 18 20:37:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674490155; cv=none; d=zohomail.com; s=zohoarc; b=QQlDrPSKG4bWGBCKz7TgyDgERcJ7n7TcNCLpH1muf09aPTWUSi4xOA3WY70sf1R5kQKuZ/QJEf9d+9akN7jnrHpjx7Q3F3I+KHq3I3+CFdedDIqSvo+6ymDu0jU2iaVCQg2Zx2esSz13BoHZbFiaWkZTbZiO9PFG5KV5Ftzz/ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674490155; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Wj6vGQkywJfVjw2xiXGmQ1QT8vp5jo6dBo3Ci55j0gc=; b=Q5cUFfSDwxxwhl2xW0PWgmA5DwsB05c8JzHHOVSa7/vAPZUHxn0nw1lyyRfoL9Q6dKgnkWxhzzCVH9qnZevsqBqFPY9rCZi9LbdmfFkMTWktRIEUQI+WLUvWe5j2DpHrNLb207YBr/2/Odr5oBkcC61er8HT2cn9XdcofHwFnwY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1674490155124539.9805568939671; Mon, 23 Jan 2023 08:09:15 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-VruETNcWOd-IGLZiW1BaDA-1; Mon, 23 Jan 2023 11:09:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3225C802C1D; Mon, 23 Jan 2023 16:09:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1CE8A1121339; Mon, 23 Jan 2023 16:09:06 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 7F1B419465A0; Mon, 23 Jan 2023 16:09:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0C8781946589 for ; Mon, 23 Jan 2023 16:09:04 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E700040C2004; Mon, 23 Jan 2023 16:09:03 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DD1C40C2008 for ; Mon, 23 Jan 2023 16:09:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674490153; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Wj6vGQkywJfVjw2xiXGmQ1QT8vp5jo6dBo3Ci55j0gc=; b=dXpC9YK0tLmdV5jz8j1HbN/peuG4ul0x36K0aGcXheMh2BScRKR4B/A/iZJH4IOJTM+4hW RST4uUkGS7/c/wIHfGS1J4fCPEZ6l/zq29Iap/fN4iDVf8i5wBjBuCq6s5GI7jE2EjiZw0 jtRKLHICxB+Ttp/Fou9JHCFAfJFDDeI= X-MC-Unique: VruETNcWOd-IGLZiW1BaDA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] virNetLibsshSessionAuthAddPasswordAuth: Don't access unlocked 'sess' Date: Mon, 23 Jan 2023 17:08:54 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674490156755100001 Content-Type: text/plain; charset="utf-8" '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: 6917467c2b0e8f655999f3e568708c4651811689 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetlibsshsession.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 8de7c86a41..d2e9e20ff2 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -846,16 +846,17 @@ virNetLibsshSessionAuthAddPasswordAuth(virNetLibsshSe= ssion *sess, int ret; virNetLibsshAuthMethod *auth; + virObjectLock(sess); + if (uri) { VIR_FREE(sess->authPath); if (virAuthGetConfigFilePathURI(uri, &sess->authPath) < 0) { - ret =3D -1; - goto cleanup; + virObjectUnlock(sess); + return -1; } } - virObjectLock(sess); if (!(auth =3D virNetLibsshSessionAuthMethodNew(sess))) { ret =3D -1; --=20 2.38.1 From nobody Sat May 18 20:37:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1674490161; cv=none; d=zohomail.com; s=zohoarc; b=AxxT+mOjmic2Rv1lNmuAyKLG+mHKS+kFlvmD2xDckw+NklSLTkxhJ44DsgZFKKPF7SI03xDG+K8ojcUtwUP+pVVv+Sb8qTrktzs1LbpLqZyooGLW748Bn7JEoRUR+VWktVYnCAcq7A3juCS8X8PP5TIIbS7f4WE01NzJkYWMezA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674490161; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fi2L3jSKixgHFHrQYPN0INvCJWGc1bto2u7dia8v744=; b=G+PAimPDJRLQrx2tRv7bSS/zm2mUKwQfKi0UkLktdfp2TJ/pyuVIaQ2k1Q2ADm2v2oXmfqqfsqep2G78SGbZoosrA/lMUU2AbPd3w6a0mWxIKR0jH5yAyGGGk0VwZi+POEBVlZgUo6s0LirdTQyl/+ewqZsPNSnFeL2u9FO9EFk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1674490161891816.980166980474; Mon, 23 Jan 2023 08:09:21 -0800 (PST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-41-RCsOvLlrOpyhUf1qQ7bVog-1; Mon, 23 Jan 2023 11:09:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D86285C06B; Mon, 23 Jan 2023 16:09:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 68DCB111E3E6; Mon, 23 Jan 2023 16:09:08 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 3520B194658D; Mon, 23 Jan 2023 16:09:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BB6F5194658C for ; Mon, 23 Jan 2023 16:09:06 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 916B840C2008; Mon, 23 Jan 2023 16:09:06 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-29.brq.redhat.com [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2AFE40C2004 for ; Mon, 23 Jan 2023 16:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674490160; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fi2L3jSKixgHFHrQYPN0INvCJWGc1bto2u7dia8v744=; b=V1xA7ToUmMuEZQN/TVoPOojU/kAYICrRA5qWtpIfOR9uBnv+Vf/sMh2UL0dGWe6eg1R4cO 4v5fibbBXKVDD9RWDMEK07dbKNN0f9yT9McazipOCMZFsABSyWQZk5tZVJxE9ytIX677ec VcZ9seDENS1rfnpyUeY/bmlF0X2URus= X-MC-Unique: RCsOvLlrOpyhUf1qQ7bVog-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] virnetlibsshsession: Don't check return value of 'virNetLibsshSessionAuthMethodNew' Date: Mon, 23 Jan 2023 17:08:55 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1674490162789100001 Content-Type: text/plain; charset="utf-8" The function can't return NULL to the callers so it doesn't make sense to check it. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/rpc/virnetlibsshsession.c | 43 ++++++----------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index d2e9e20ff2..bba37210df 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -843,7 +843,6 @@ int virNetLibsshSessionAuthAddPasswordAuth(virNetLibsshSession *sess, virURI *uri) { - int ret; virNetLibsshAuthMethod *auth; virObjectLock(sess); @@ -857,43 +856,27 @@ virNetLibsshSessionAuthAddPasswordAuth(virNetLibsshSe= ssion *sess, } } - - if (!(auth =3D virNetLibsshSessionAuthMethodNew(sess))) { - ret =3D -1; - goto cleanup; - } - + auth =3D virNetLibsshSessionAuthMethodNew(sess); auth->method =3D VIR_NET_LIBSSH_AUTH_PASSWORD; auth->ssh_flags =3D SSH_AUTH_METHOD_PASSWORD; - ret =3D 0; - - cleanup: virObjectUnlock(sess); - return ret; + return 0; } int virNetLibsshSessionAuthAddAgentAuth(virNetLibsshSession *sess) { - int ret; virNetLibsshAuthMethod *auth; virObjectLock(sess); - if (!(auth =3D virNetLibsshSessionAuthMethodNew(sess))) { - ret =3D -1; - goto cleanup; - } - + auth =3D virNetLibsshSessionAuthMethodNew(sess); auth->method =3D VIR_NET_LIBSSH_AUTH_AGENT; auth->ssh_flags =3D SSH_AUTH_METHOD_PUBLICKEY; - ret =3D 0; - - cleanup: virObjectUnlock(sess); - return ret; + return 0; } int @@ -910,11 +893,7 @@ virNetLibsshSessionAuthAddPrivKeyAuth(virNetLibsshSess= ion *sess, virObjectLock(sess); - if (!(auth =3D virNetLibsshSessionAuthMethodNew(sess))) { - virObjectUnlock(sess); - return -1; - } - + auth =3D virNetLibsshSessionAuthMethodNew(sess); auth->filename =3D g_strdup(keyfile); auth->method =3D VIR_NET_LIBSSH_AUTH_PRIVKEY; auth->ssh_flags =3D SSH_AUTH_METHOD_PUBLICKEY; @@ -927,26 +906,18 @@ int virNetLibsshSessionAuthAddKeyboardAuth(virNetLibsshSession *sess, int tries) { - int ret; virNetLibsshAuthMethod *auth; virObjectLock(sess); - if (!(auth =3D virNetLibsshSessionAuthMethodNew(sess))) { - ret =3D -1; - goto cleanup; - } + auth =3D virNetLibsshSessionAuthMethodNew(sess); auth->tries =3D tries; auth->method =3D VIR_NET_LIBSSH_AUTH_KEYBOARD_INTERACTIVE; auth->ssh_flags =3D SSH_AUTH_METHOD_INTERACTIVE; - ret =3D 0; - - cleanup: virObjectUnlock(sess); - return ret; - + return 0; } void --=20 2.38.1