From nobody Mon Apr 29 09:32:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1515773358495427.41868742264603; Fri, 12 Jan 2018 08:09:18 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8EA43A1F69; Fri, 12 Jan 2018 16:09:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C58D8179E9; Fri, 12 Jan 2018 16:09:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3E3473FAE1; Fri, 12 Jan 2018 16:09:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0CG8pOD011870 for ; Fri, 12 Jan 2018 11:08:52 -0500 Received: by smtp.corp.redhat.com (Postfix) id 78C6C17585; Fri, 12 Jan 2018 16:08:51 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id F20A9174B5 for ; Fri, 12 Jan 2018 16:08:47 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 12 Jan 2018 17:08:42 +0100 Message-Id: <43104c3ff056df09b63b5cf92bf4e35b2ec38d31.1515773322.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] vshReadlineOptionsPrune: Fix possible leak 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 12 Jan 2018 16:09:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The function should prune list of --options so that options already specified are not offered to user for completion again. However, if the list of offered options contains a string that doesn't start with double dash the function returns leaking partially constructed list. There's not much benefit from trying to roll back. Just free everything up - our only caller would do that anyway. Signed-off-by: Michal Privoznik --- tools/vsh.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/vsh.c b/tools/vsh.c index 4426c08d6..7db0a16f1 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2798,8 +2798,17 @@ vshReadlineOptionsPrune(char ***list, vshCmdOpt *opt =3D last->opts; =20 /* Should never happen (TM) */ - if (!list_opt) + if (!list_opt) { + /* But in case it does, we're in a tough situation + * because @list[0..i-1] is possibly sparse. That + * means if caller were to call virStringListFree + * over it some memory is definitely going to be + * leaked. The best we can do is to free from list[i] + * as our only caller is just fine with it. */ + virStringListFree(list[i]); + virStringListFree(newList); return -1; + } =20 while (opt) { if (STREQ(opt->def->name, list_opt)) { --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list