From nobody Tue Feb 10 03:45:23 2026 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=1621350344; cv=none; d=zohomail.com; s=zohoarc; b=BeHw01QSVmW9Nq3eEm33mUrOYwfhGEsgof7mB1N+RvnZ12CynK6HGwGPaxuH4f5NIVWHLqBgjUZmQhNyBLWL06f5oLmL6yVoNEXhp+yiQ0o5pzm2ddSrpPjFye5oh88hdj9nZbmN21zSvaBUuny9AhP/tvN+nwG/vC7bUkZNjwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621350344; h=Content-Type:Content-Transfer-Encoding:Cc: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=OpiW+X7OaTaDI4S2QMwHARRdSuaIL10zyrSG/mL+3+s=; b=nEcIB4Zs3bAiIK7xZM1oDpfi6rN1EMHi7Ujp3S58U0rkloaRb8StBntzaLRvgKjz35Lx0XgXorjDM1rCoMkgNsJg0EQWoQFm+QEo2jPnfvRKJgFQPQWeJkGLUjVHfiHJOtf1XEDN8xTD6My4srDZhubNo8WovPvz20YKWsb+/2M= 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 1621350344401615.0940663890219; Tue, 18 May 2021 08:05:44 -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-170-sp4AbmGfNWalyXzPJ6Gfcw-1; Tue, 18 May 2021 11:05:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 98A41E7B4C; Tue, 18 May 2021 15:05:26 +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 7D02D18A50; Tue, 18 May 2021 15:05:26 +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 437E01801265; Tue, 18 May 2021 15:05:26 +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 14IF4w0Y019279 for ; Tue, 18 May 2021 11:04:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 536893CC7; Tue, 18 May 2021 15:04:58 +0000 (UTC) Received: from work.redhat.com (ovpn-113-109.ams2.redhat.com [10.36.113.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C3A619D7C; Tue, 18 May 2021 15:04:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621350341; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=OpiW+X7OaTaDI4S2QMwHARRdSuaIL10zyrSG/mL+3+s=; b=fEKIM5qC1D/rW0jCCxJf5U5zky3MU3TwefbHu34pbmxjLsAU4Y9vzEalnv1NO/3/XoDnn1 Lgc7w/wfO/5EZdcPMc/AZHgYvtHBgs8DhLo6HIZ3GgLDT905zufuflW8Neb2RhdoQeEaQU B9tOaE+rgCWOYy9dTkM1YQo9rsTx8Lw= X-MC-Unique: sp4AbmGfNWalyXzPJ6Gfcw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 05/10] virDomainDiskDefGeometryParse: Use virXMLProp* Date: Tue, 18 May 2021 17:04:46 +0200 Message-Id: <20210518150451.79954-6-twiederh@redhat.com> In-Reply-To: <20210518150451.79954-1-twiederh@redhat.com> References: <20210518150451.79954-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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" This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attributes `cyls`, `heads` and `secs`. Allowing negative numbers to be interpreted this way makes no sense for these attributes. Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 48 +++++++++++------------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f55117e849..bfcc56ca9e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8815,45 +8815,21 @@ static int virDomainDiskDefGeometryParse(virDomainDiskDef *def, xmlNodePtr cur) { - g_autofree char *tmp =3D NULL; - - if ((tmp =3D virXMLPropString(cur, "cyls"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.cylinders) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (cyls)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "cyls", 10, VIR_XML_PROP_NONE, + &def->geometry.cylinders) < 0) + return -1; =20 - if ((tmp =3D virXMLPropString(cur, "heads"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.heads) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (heads)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "heads", 10, VIR_XML_PROP_NONE, + &def->geometry.heads) < 0) + return -1; =20 - if ((tmp =3D virXMLPropString(cur, "secs"))) { - if (virStrToLong_ui(tmp, NULL, 10, &def->geometry.sectors) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid geometry settings (secs)")); - return -1; - } - VIR_FREE(tmp); - } + if (virXMLPropUInt(cur, "secs", 10, VIR_XML_PROP_NONE, + &def->geometry.sectors) < 0) + return -1; =20 - if ((tmp =3D virXMLPropString(cur, "trans"))) { - int value; - if ((value =3D virDomainDiskGeometryTransTypeFromString(tmp)) <=3D= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid translation value '%s'"), - tmp); - return -1; - } - def->geometry.trans =3D value; - } + if (virXMLPropEnum(cur, "trans", virDomainDiskGeometryTransTypeFromStr= ing, + VIR_XML_PROP_NONZERO, &def->geometry.trans) < 0) + return -1; =20 return 0; } --=20 2.26.3