From nobody Wed Apr 24 21:32:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) client-ip=209.132.183.39; envelope-from=libvir-list-bounces@redhat.com; helo=mx6-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.39 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) by mx.zohomail.com with SMTPS id 1487263456805856.7667798544478; Thu, 16 Feb 2017 08:44:16 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1GGeBrT048520; Thu, 16 Feb 2017 11:40:11 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v1GGe9WQ024641 for ; Thu, 16 Feb 2017 11:40:09 -0500 Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1GGe95N019418 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 16 Feb 2017 11:40:09 -0500 Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 906DD3A7694; Thu, 16 Feb 2017 16:40:07 +0000 (UTC) Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v1GGe5Yp030588 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Feb 2017 16:40:05 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id v1GGe4S7002723 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Feb 2017 16:40:05 GMT Received: from abhmp0007.oracle.com (abhmp0007.oracle.com [141.146.116.13]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v1GGe40G020100; Thu, 16 Feb 2017 16:40:04 GMT Received: from paddy.lan (/89.114.92.174) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Feb 2017 08:40:04 -0800 From: Joao Martins To: Libvirt Development List Date: Thu, 16 Feb 2017 16:43:05 +0000 Message-Id: <1487263385-27855-1-git-send-email-joao.m.martins@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 200 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 16 Feb 2017 16:40:07 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 16 Feb 2017 16:40:07 +0000 (UTC) for IP:'141.146.126.69' DOMAIN:'aserp1040.oracle.com' HELO:'aserp1040.oracle.com' FROM:'joao.m.martins@oracle.com' RCPT:'' X-RedHat-Spam-Score: -104.897 (BAYES_50, DCC_REPUT_13_19, RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H2, RP_MATCHES_RCVD, SPF_PASS, UNPARSEABLE_RELAY, USER_IN_WHITELIST) 141.146.126.69 aserp1040.oracle.com 141.146.126.69 aserp1040.oracle.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-loop: libvir-list@redhat.com Cc: Joao Martins Subject: [libvirt] [PATCH] libxl: fix coverity issues introduced by 6a95edf X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As discussed here [0][1] Coverity reported two issues: - On libxlDomainMigrationPrepareTunnel3 @@mig will be leaked on failures after sucessfull call libxlDomainMigrationPrepareAny hence we free it. Setting mig =3D NULL after @mig is assigned plus adding libxlMigrationCooki= eFree on error paths addresses the issue. In case virThreadCreate fails, unref of args frees the cookie on dispose function (libxlMigrationDstArgsDi= spose) - On libxlMigrationStartTunnel @tc would be leaked. Fixed by correctly saving the newly allocated @tc onto @tnl such that libxlMigrationStopTunnel would free it up. [0] https://www.redhat.com/archives/libvir-list/2017-February/msg00791.html [1] https://www.redhat.com/archives/libvir-list/2017-February/msg00833.html Signed-off-by: Joao Martins --- Cc: John Ferlan Cc: Jim Fehlig --- src/libxl/libxl_migration.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index ba1ca5c..fb833d1 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -617,6 +617,8 @@ libxlDomainMigrationPrepareTunnel3(virConnectPtr dconn, /* Receive from pipeOut */ args->recvfd =3D dataFD[0]; args->nsocks =3D 0; + mig =3D NULL; + if (virThreadCreate(&thread, false, libxlDoMigrateReceive, args) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("Failed to create thread for receiving migration = data")); @@ -627,6 +629,7 @@ libxlDomainMigrationPrepareTunnel3(virConnectPtr dconn, goto done; =20 error: + libxlMigrationCookieFree(mig); VIR_FORCE_CLOSE(dataFD[1]); VIR_FORCE_CLOSE(dataFD[0]); virObjectUnref(args); @@ -907,13 +910,15 @@ libxlMigrationStartTunnel(libxlDriverPrivatePtr drive= r, virDomainObjPtr vm, unsigned long flags, virStreamPtr st, - struct libxlTunnelControl *tc) + struct libxlTunnelControl **tnl) { + struct libxlTunnelControl *tc =3D NULL; libxlTunnelMigrationThread *arg =3D NULL; int ret =3D -1; =20 if (VIR_ALLOC(tc) < 0) goto out; + *tnl =3D tc; =20 tc->dataFD[0] =3D -1; tc->dataFD[1] =3D -1; @@ -1045,7 +1050,7 @@ libxlDoMigrateP2P(libxlDriverPrivatePtr driver, =20 VIR_DEBUG("Perform3 uri=3D%s", NULLSTR(uri_out)); if (flags & VIR_MIGRATE_TUNNELLED) - ret =3D libxlMigrationStartTunnel(driver, vm, flags, st, tc); + ret =3D libxlMigrationStartTunnel(driver, vm, flags, st, &tc); else ret =3D libxlDomainMigrationPerform(driver, vm, NULL, NULL, uri_out, NULL, flags); --=20 2.1.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list