From nobody Wed May 15 19:22:45 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=1618813525; cv=none; d=zohomail.com; s=zohoarc; b=Otir6EP7GUmwjxiRAp1mXoKHFrXaoM3GdFL2kIHygSPzQgnkfqKXB2/QPPpoVqD+z3bGyjYdRVCksZpjrLZ0Qh027hAahgQNK5pGf4aF6B7jYlEtuOty+8kRD36Dv9b5tYBZZZ5P9U+FsKSLw5IXQllp5/xqYqKRzFH2Uncib0A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618813525; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=I5FsQWvaInvoaePaq+vc9ciOYvZxBfdQfP21yxsK0PQ=; b=RU7DnbN3Wx+aUNms/NvkczTWCECDoT7sYupSd4CVQKGpV17VxG6tG1j6s6SmDE1qL7fZ6XXNh/zm/rpk2uxwZGkWEgAeuh3IBInHZu7Djv/tWez2KlHaaNjbvaRaG8MoluDyhpM8BBhSib/oa+1yMNR+de/FUr+bx62ITIdJCy0= 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) header.from= 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 1618813525172944.9418290583245; Sun, 18 Apr 2021 23:25:25 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-20-R_6FFOWGOqaxwmpfToxrhQ-1; Mon, 19 Apr 2021 02:25:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BE77817469; Mon, 19 Apr 2021 06:25:15 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A4955D71D; Mon, 19 Apr 2021 06:25:13 +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 D90C71806D17; Mon, 19 Apr 2021 06:25:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13J6P6mP011386 for ; Mon, 19 Apr 2021 02:25:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 952BC1A26A; Mon, 19 Apr 2021 06:25:06 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id E16331F05A for ; Mon, 19 Apr 2021 06:25:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618813524; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=I5FsQWvaInvoaePaq+vc9ciOYvZxBfdQfP21yxsK0PQ=; b=ZS5ECLoeku3KjrphDYBWGecUEfCgEI/qPzZzdZc5qZaPexanNdTMlV5BEFbMVjMG3M5woR M3mCu7djhURUDpA3SYUTQrGbwihu0c590HmSG4AGAjvrxSpxXxSEIuGksTGGzKH/Cv8XsK SD/aWtz7XXyLyQIELX5jNTaWQFjiAB0= X-MC-Unique: R_6FFOWGOqaxwmpfToxrhQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH] cmdDomBlkError: Fix crash when initial call to virDomainGetDiskErrors fails Date: Mon, 19 Apr 2021 08:25:00 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" virDomainGetDiskErrors uses the weird semantics where we make the caller query for the number of elements and then pass pre-allocated structure. The cleanup section errorneously used the 'count' variable to free the allocated elements for the API but 'count' can be '-1' in cases when the API returns failure, thus attempting to free beyond the end of the array. Resolves: https://gitlab.com/libvirt/libvirt/-/issues/155 Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- tools/virsh-domain-monitor.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0e49f5da8a..a2bf5c05fc 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1220,7 +1220,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; virDomainDiskErrorPtr disks =3D NULL; - unsigned int ndisks; + unsigned int ndisks =3D 0; size_t i; int count; bool ret =3D false; @@ -1230,10 +1230,10 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) if ((count =3D virDomainGetDiskErrors(dom, NULL, 0, 0)) < 0) goto cleanup; - ndisks =3D count; - if (ndisks) { - disks =3D g_new0(virDomainDiskError, ndisks); + if (count > 0) { + disks =3D g_new0(virDomainDiskError, count); + ndisks =3D count; if ((count =3D virDomainGetDiskErrors(dom, disks, ndisks, 0)) =3D= =3D -1) goto cleanup; @@ -1252,7 +1252,7 @@ cmdDomBlkError(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: - for (i =3D 0; i < count; i++) + for (i =3D 0; i < ndisks; i++) VIR_FREE(disks[i].disk); VIR_FREE(disks); virshDomainFree(dom); --=20 2.30.2