From nobody Fri Apr 19 18:29:52 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=1637845166; cv=none; d=zohomail.com; s=zohoarc; b=b4S81r1CWJPy8DIX4N4rEDNW19lGllS76pwLFjlQg0atMLNxJ9lCUIGMqQ9svaa6dLI3slU8OOwYD0ez4TAjx172P/X3laAT1/0lTaowUZqXiR+XA6R86ivjEqyZZQN69hQ3WVWsIcUdj+y/n2CeRoPFzLRwHyLMKfSuaPaEkVI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845166; 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=3sP6hE1TWlC+7PKBTnDCUQEutZkRjM4L9JDFEHSVOCo=; b=Nedu94y+FtTF7dCIgXG6UpRaaxC/wgjqH54oXWeB4h9NFtRvKABdESHE+w3ZxHQRk9KEixabrJNzQngeOoMes4v1RNKxuC2cwxZpdezaysDxAbF2HSvg5D//i4KXXvzm3gsDkXOAjg+uEbi72MXF4ImLtyxElI8wfBYIEufKU4I= 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 1637845166481453.5968842718721; Thu, 25 Nov 2021 04:59:26 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-506-Wpu0u3RJP3CWirl9sLSEoA-1; Thu, 25 Nov 2021 07:59:23 -0500 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 1D69F1023F4E; Thu, 25 Nov 2021 12:59:19 +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 EEAE65D740; Thu, 25 Nov 2021 12:59:18 +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 74CCE1809C8A; Thu, 25 Nov 2021 12:59:17 +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 1APCxEus030979 for ; Thu, 25 Nov 2021 07:59:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 98A4C5F4EF; Thu, 25 Nov 2021 12:59:14 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05FD05D740 for ; Thu, 25 Nov 2021 12:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845165; 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=3sP6hE1TWlC+7PKBTnDCUQEutZkRjM4L9JDFEHSVOCo=; b=Kl6opXyBLBAYJQhPeR0XuyZmOH7NeIxEnvBTARYY27j+RlXlUCdFtVpcx6qlOqgP0o/cHq AolnJDQ8lnvixG6xw3orxjS94KQJa2fmStB76P2kbmdEp8TElvbtdskQecSCZE9lP0nzRV 3//aMFiuUiraCKVY2CPvtwCGDjuRctA= X-MC-Unique: Wpu0u3RJP3CWirl9sLSEoA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/6] util: enum: Add helpers for converting virTristate* to a plain bool Date: Thu, 25 Nov 2021 13:59:06 +0100 Message-Id: <3184b5e4aab3b02a827f1972447208af022f131c.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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) X-ZM-MESSAGEID: 1637845166991100003 Content-Type: text/plain; charset="utf-8" The helpers will update the passed boolean if the tristate's value is not _ABSENT. Signed-off-by: Peter Krempa --- src/libvirt_private.syms | 2 ++ src/util/virenum.c | 54 ++++++++++++++++++++++++++++++++++++++++ src/util/virenum.h | 2 ++ 3 files changed, 58 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b98cb0f66d..49795e5b81 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2147,9 +2147,11 @@ ebtablesRemoveForwardAllowIn; virEnumFromString; virEnumToString; virTristateBoolFromBool; +virTristateBoolToBool; virTristateBoolTypeFromString; virTristateBoolTypeToString; virTristateSwitchFromBool; +virTristateSwitchToBool; virTristateSwitchTypeFromString; virTristateSwitchTypeToString; diff --git a/src/util/virenum.c b/src/util/virenum.c index 26093bd795..103f00b524 100644 --- a/src/util/virenum.c +++ b/src/util/virenum.c @@ -47,6 +47,33 @@ virTristateBoolFromBool(bool val) } +/** + * virTristateBoolToBool: + * @t: a virTristateBool value + * @b: pointer to a boolean to be updated according to the value of @t + * + * The value pointed to by @b is updated if the tristate value @t is not a= bsent. + */ +void +virTristateBoolToBool(virTristateBool t, + bool *b) +{ + switch (t) { + case VIR_TRISTATE_BOOL_YES: + *b =3D true; + break; + + case VIR_TRISTATE_BOOL_NO: + *b =3D false; + break; + + case VIR_TRISTATE_BOOL_ABSENT: + case VIR_TRISTATE_BOOL_LAST: + break; + } +} + + virTristateSwitch virTristateSwitchFromBool(bool val) { @@ -57,6 +84,33 @@ virTristateSwitchFromBool(bool val) } +/** + * virTristateSwitchToBool: + * @t: a virTristateSwitch value + * @b: pointer to a boolean to be updated according to the value of @t + * + * The value pointed to by @b is updated if the tristate value @t is not a= bsent. + */ +void +virTristateSwitchToBool(virTristateSwitch t, + bool *b) +{ + switch (t) { + case VIR_TRISTATE_SWITCH_ON: + *b =3D true; + break; + + case VIR_TRISTATE_SWITCH_OFF: + *b =3D false; + break; + + case VIR_TRISTATE_SWITCH_ABSENT: + case VIR_TRISTATE_SWITCH_LAST: + break; + } +} + + int virEnumFromString(const char * const *types, unsigned int ntypes, diff --git a/src/util/virenum.h b/src/util/virenum.h index d74af35530..98f01d574d 100644 --- a/src/util/virenum.h +++ b/src/util/virenum.h @@ -68,7 +68,9 @@ VIR_ENUM_DECL(virTristateBool); VIR_ENUM_DECL(virTristateSwitch); virTristateBool virTristateBoolFromBool(bool val); +void virTristateBoolToBool(virTristateBool t, bool *b); virTristateSwitch virTristateSwitchFromBool(bool val); +void virTristateSwitchToBool(virTristateSwitch t, bool *b); /* the two enums must be in sync to be able to use helpers interchangeably= in * some special cases */ --=20 2.31.1 From nobody Fri Apr 19 18:29:52 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=1637845171; cv=none; d=zohomail.com; s=zohoarc; b=mOuz6IYA/ByFMKr12aoEWxNylubZvuoTSwxq82awzp3EtryrIU+ewfWyWDVWaj8TYMZs0MXhkoXRvJYrJ7aL/SPB/cY7zBZb4I7CLLAn8n+XNaF3k+u1875dOwF3EOn3XE7elYUv83ehcKF/r6hDI7iXcKIumb3BQ5UBpj/n114= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845171; 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=BvmsshhNFYuSt5jKJErG4SEKFw6cVYNFRKk7Nkdbfds=; b=KevXdhi/ow0LAoCing+A4rWYpfDxBOX+pjdDOA9VyxEc9PBsXG3DA+KpLHvqrNjvI66jiwc8Bhk1d15XiiS4iYKCqywcT2bqgrEY9juiaMgi0+9i0xQENMrEYJnG7FDhFimRMHW1fMCPAPFVBhHvzhLGrJ4WLwc3FU+UWs3Ls0Y= 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 1637845171255107.91548524447649; Thu, 25 Nov 2021 04:59:31 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-150-6i3Pt2iPPRqx_2LrlIwlUw-1; Thu, 25 Nov 2021 07:59:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0A89E2F21; Thu, 25 Nov 2021 12:59:22 +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 C07D560C4A; Thu, 25 Nov 2021 12:59:21 +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 76B151809CB7; Thu, 25 Nov 2021 12:59:21 +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 1APCxFwj030990 for ; Thu, 25 Nov 2021 07:59:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB0EF5D740; Thu, 25 Nov 2021 12:59:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06FA75F4EF for ; Thu, 25 Nov 2021 12:59:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845170; 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=BvmsshhNFYuSt5jKJErG4SEKFw6cVYNFRKk7Nkdbfds=; b=c8TTxKhALDRaKnXaKkDmVqbAZPtV/u3LkK3l0Rbb2ZNhX29ye4Hos54j1CP1F4bmUTwYFh dJwTTcdjrKcI5QE2IEXR0svaXBsco2mp0L2/717yUH/RJjdGe9dM0LYbUbRg9HsPtcImGy akJMg84I4VpgySZC4HKUEmX4iL+4pyY= X-MC-Unique: 6i3Pt2iPPRqx_2LrlIwlUw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/6] conf: seclabel: Parse booleans using virXMLPropTristateBool instead of virStringParseYesNo Date: Thu, 25 Nov 2021 13:59:07 +0100 Message-Id: <42b87672fdc30b6d46209b5705561d6ede7b33c5.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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) X-ZM-MESSAGEID: 1637845172030100001 Content-Type: text/plain; charset="utf-8" Reduce the extent of custom logcic and custom error messages by using virXMLPropTristateBool. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f88405ab02..0203d17e9d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7801,7 +7801,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, unsigned int flags) { g_autofree char *model =3D NULL; - g_autofree char *relabel =3D NULL; + virTristateBool relabel =3D VIR_TRISTATE_BOOL_ABSENT; g_autoptr(virSecurityLabelDef) seclabel =3D NULL; if ((model =3D virXMLPropString(ctxt->node, "model")) && @@ -7824,13 +7824,10 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_NONE) seclabel->relabel =3D false; - if ((relabel =3D virXMLPropString(ctxt->node, "relabel"))) { - if (virStringParseYesNo(relabel, &seclabel->relabel) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid security relabel value '%s'"), relab= el); - return NULL; - } - } + if (virXMLPropTristateBool(ctxt->node, "relabel", VIR_XML_PROP_NONZERO= , &relabel) < 0) + return NULL; + + virTristateBoolToBool(relabel, &seclabel->relabel); if (seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC && !seclabel->relabel) { @@ -8029,9 +8026,8 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDef ***seclabels_rtn, for (i =3D 0; i < n; i++) { g_autofree char *model =3D NULL; - g_autofree char *relabel =3D NULL; g_autofree char *label =3D NULL; - g_autofree char *labelskip =3D NULL; + virTristateBool t; /* get model associated to this override */ model =3D virXMLPropString(list[i], "model"); @@ -8047,23 +8043,20 @@ virSecurityDeviceLabelDefParseXML(virSecurityDevice= LabelDef ***seclabels_rtn, seclabels[i]->model =3D g_steal_pointer(&model); } - relabel =3D virXMLPropString(list[i], "relabel"); - if (relabel !=3D NULL) { - if (virStringParseYesNo(relabel, &seclabels[i]->relabel) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid security relabel value %s"), - relabel); - goto error; - } - } else { - seclabels[i]->relabel =3D true; - } + if (virXMLPropTristateBool(list[i], "relabel", VIR_XML_PROP_NONZER= O, &t) < 0) + goto error; + + seclabels[i]->relabel =3D true; + virTristateBoolToBool(t, &seclabels[i]->relabel); /* labelskip is only parsed on live images */ - labelskip =3D virXMLPropString(list[i], "labelskip"); seclabels[i]->labelskip =3D false; - if (labelskip && !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - ignore_value(virStringParseYesNo(labelskip, &seclabels[i]->lab= elskip)); + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { + if (virXMLPropTristateBool(list[i], "labelskip", VIR_XML_PROP_= NONZERO, &t) < 0) + goto error; + + virTristateBoolToBool(t, &seclabels[i]->labelskip); + } ctxt->node =3D list[i]; label =3D virXPathString("string(./label)", ctxt); --=20 2.31.1 From nobody Fri Apr 19 18:29:52 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=1637845176; cv=none; d=zohomail.com; s=zohoarc; b=YTDNy2g5Mu+Oj+j1w5Y9BzGS2NXhwv8Z7CiBuQSQoVdoNoFhctiprCFEhIlay1640PyJrBts1QGdZ5tywMJkra2QXdrEf4dj/UxjoxWQb+6Ux//xEJMROuwx0Cy95ZXY2vJ6prGdDHLPOgtAQdx0MJa8T/3tQJ0cDZg8nrLL6PE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845176; 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=FyHC4vYudY/Z38uwn8ipJca/V+AHud9XjYjCGH1gAsE=; b=fKStt43ZV59IpW1gUQAQKIKouqyy+MrxbsoOZDoMFvA5cThFZvFprPBMGlBs0HO0FZqL+Cw49iLtgGX1r2sTBDtbY2gZRBzvjsjIYmnfFnuDq42MJpSy1BORI7W7af02HemOVb9/Ytvxmvt1Til3ldRNYMQIDDzLnnYmn3joUvY= 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 1637845176851378.3089692561563; Thu, 25 Nov 2021 04:59:36 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-HBRnHq4FPa21kWaLUNB9fA-1; Thu, 25 Nov 2021 07:59:32 -0500 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 532472F26; Thu, 25 Nov 2021 12:59:27 +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 363155F4F4; Thu, 25 Nov 2021 12:59:27 +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 010404A7CA; Thu, 25 Nov 2021 12:59:26 +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 1APCxGEU030995 for ; Thu, 25 Nov 2021 07:59:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id BAE685D740; Thu, 25 Nov 2021 12:59:16 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 237D45F4EF for ; Thu, 25 Nov 2021 12:59:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845175; 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=FyHC4vYudY/Z38uwn8ipJca/V+AHud9XjYjCGH1gAsE=; b=LOiys51FJMP2xVtOR+ADz1u6tB1kkatGzoTvba62YXgB7fuuuGT/Y7FV52HhPzNIiO0fbV +2kM3L9lJcddUTCdg/+UqYOREm/Em48lFHZfeeYMH1kMmxEbIOmDMKZKFsjs4JrP78V+Pb 4zD47ky6nz0yrk2vW68END5sPu/QGYs= X-MC-Unique: HBRnHq4FPa21kWaLUNB9fA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/6] internal: Add STRLIM macro for checking string length using strnlen() Date: Thu, 25 Nov 2021 13:59:08 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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) X-ZM-MESSAGEID: 1637845177098100003 Content-Type: text/plain; charset="utf-8" As a microoprimization when checking whether length of a string fits into a limit we don't necessarily need to calculate the full lenght but can use strnlen to check only LIMIT+1 chars. Add a macro which will simplify the expressions. Signed-off-by: Peter Krempa --- src/internal.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/internal.h b/src/internal.h index d3809bf057..2e404cd705 100644 --- a/src/internal.h +++ b/src/internal.h @@ -87,6 +87,15 @@ #define STRPREFIX(a, b) (strncmp(a, b, strlen(b)) =3D=3D 0) #define STRCASEPREFIX(a, b) (g_ascii_strncasecmp(a, b, strlen(b)) =3D=3D 0) #define STRSKIP(a, b) (STRPREFIX(a, b) ? (a) + strlen(b) : NULL) +/** + * STRLIM + * @str: pointer to a string (evaluated once) + * @lim: length limit (evaluated twice) + * + * Evaluates as true if length of @str doesn't exceed the limit @lim. Note + * that @lim + 1 characters may be accessed. + */ +#define STRLIM(str, lim) (strnlen((str), (lim) + 1) <=3D (lim)) #define STREQ_NULLABLE(a, b) (g_strcmp0(a, b) =3D=3D 0) #define STRNEQ_NULLABLE(a, b) (g_strcmp0(a, b) !=3D 0) --=20 2.31.1 From nobody Fri Apr 19 18:29:52 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=1637845177; cv=none; d=zohomail.com; s=zohoarc; b=bx8Qnnf9GAJICt8zHkQWoQ7cfMLwgP82ae+eHCgbXyj6BlWxYSwL9z+5DWPRvU2CcsoILj1I3mbzPPeyFMsrzqMs2UgygMVUEJtPYFoWaACf+XZxUTrFuMmg/e3gplswRQT2ZoWI1bdo+I1lJoM7I/EJ/2HW6VzutB7tyIzcRGY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845177; 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=Phnm07G1TXJ4RtjN/wH5ENG9JtLDDxd2c++8OpVzdz0=; b=dNNFRMgNQ27ydV7yiyWYw7/KwHXW1zIV4Xg/h27G0dbDeqv7n2kcvxox5ULE5n4kgjQPmkGN2QU2PAGEZGoeguOmGzVRwSKYHT9Srfq2MpFFe3z6IX18cDAIJPGFSNajQ5l8MG3J92MpMWwv/vQ6mN0ReUWUjQQYGhuJr/YviU8= 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 1637845177124997.137047755857; Thu, 25 Nov 2021 04:59:37 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-155-T9MpvDwPM9SUUkE20PNZYA-1; Thu, 25 Nov 2021 07:59:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F2C6283DD20; Thu, 25 Nov 2021 12:59:29 +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 D572F3E38; Thu, 25 Nov 2021 12:59:29 +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 A942F1809C8A; Thu, 25 Nov 2021 12:59:29 +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 1APCxHrG031003 for ; Thu, 25 Nov 2021 07:59:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id D212C5F4F4; Thu, 25 Nov 2021 12:59:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3482E5F4EF for ; Thu, 25 Nov 2021 12:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845176; 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=Phnm07G1TXJ4RtjN/wH5ENG9JtLDDxd2c++8OpVzdz0=; b=D7mgzvp14zhBIBC8Na15Cuhy7D6A3YCs05nATG3zHY4IH0q2kR7f5tIUafbixh44z0O+vt oQc19faEFyNYyqGWqvnXdyb3gsDYaA//lAW2GyvLwbAgOkScGenEkWQ0VZscOq5gI2Ra33 Ewf+XE+ArlBHn5ik0HdMN1HCVak/Ap4= X-MC-Unique: T9MpvDwPM9SUUkE20PNZYA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/6] virDomainDeviceLoadparmIsValid: Simplify value lenght check Date: Thu, 25 Nov 2021 13:59:09 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.23 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) X-ZM-MESSAGEID: 1637845179075100005 Content-Type: text/plain; charset="utf-8" Use the new STRLIM macro and unify it with the empty string check. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 11 +++-------- .../machine-loadparm-s390-len-invalid.err | 2 +- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0203d17e9d..c542782750 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6300,15 +6300,10 @@ virDomainDeviceLoadparmIsValid(const char *loadparm) { size_t i; - if (virStringIsEmpty(loadparm)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("loadparm cannot be an empty string")); - return false; - } - - if (strlen(loadparm) > 8) { + if (virStringIsEmpty(loadparm) || !STRLIM(loadparm, 8)) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("loadparm '%s' exceeds 8 characters"), loadparm); + _("loadparm value '%s' must be between 1 and 8 char= acters"), + loadparm); return false; } diff --git a/tests/qemuxml2argvdata/machine-loadparm-s390-len-invalid.err b= /tests/qemuxml2argvdata/machine-loadparm-s390-len-invalid.err index 9afaa68ae2..9fd0425f20 100644 --- a/tests/qemuxml2argvdata/machine-loadparm-s390-len-invalid.err +++ b/tests/qemuxml2argvdata/machine-loadparm-s390-len-invalid.err @@ -1 +1 @@ -internal error: loadparm 'LOADPARM1' exceeds 8 characters +internal error: loadparm value 'LOADPARM1' must be between 1 and 8 charact= ers --=20 2.31.1 From nobody Fri Apr 19 18:29:52 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=1637845175; cv=none; d=zohomail.com; s=zohoarc; b=gJVrx0pTSkVeSZ2/dbKHxYRzVTUKxzIY95EtUGSJATFGAytVaISZqeMAAmFY01HC0hZx+yW4YL2S73LqyqucvWxFWscJlPLPEYhYwlzYFANtyH5Dd6S5+segxB9K//gnvAyGWCnSmwcR9h/7pCPmakZabT267a0ALyPtu2HDchY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845175; 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=OvHjINTvrjVq4yNWb+4K0uGLfRp2WzOKM/tg5aB3eKQ=; b=ULPua/VT20Pl1IkK4B6RPgDeo6iU0CTAncCI7mcHDjKlOwSw7igEvlFfi/dgfYeltORLIGE3U9Bg6GKVSe02964+uZaIyjt3xZhJJwg7k52/7GgT4OA4VJusRe18cB/Fe7crmQ6Yw0F8BxHUO2JW0XC7ANpH4wGROmeRJ7I8LDA= 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 1637845175555108.37860266359894; Thu, 25 Nov 2021 04:59:35 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-287-lZDwVSPLMDWHbxfGtFQHuQ-1; Thu, 25 Nov 2021 07:59:33 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 519A081CCB4; Thu, 25 Nov 2021 12:59:27 +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 321FC100AE22; Thu, 25 Nov 2021 12:59:27 +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 0084C4A7C9; Thu, 25 Nov 2021 12:59:26 +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 1APCxJJi031019 for ; Thu, 25 Nov 2021 07:59:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id F3D7E5F4F4; Thu, 25 Nov 2021 12:59:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4A4C95F4EF for ; Thu, 25 Nov 2021 12:59:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845174; 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=OvHjINTvrjVq4yNWb+4K0uGLfRp2WzOKM/tg5aB3eKQ=; b=B3GDzMNQM/vfRENqF5ChKtJLIAoU1nW6ZKsbzgmVl3pnO/oTk7cO9eIdPcFmoi3399Cixu HmT+gGvvaVemI2tBZkay7yzGlh3npiVp3tgEEcTfn0vmHd3CAn5gh/nChSpAQ4pXI1qTDI vJuDiUUnaXrqFT+SH3r9j0l0Yr9OksY= X-MC-Unique: lZDwVSPLMDWHbxfGtFQHuQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/6] virDomainDeviceLoadparmIsValid: Use 'strspn' instead of a loop Date: Thu, 25 Nov 2021 13:59:10 +0100 Message-Id: <6cc02d3315b9ca83fac4bd22d07e48dce9c9ee47.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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) X-ZM-MESSAGEID: 1637845176833100001 Content-Type: text/plain; charset="utf-8" In other places we use strspn to validate a character subset. Convert the in-place loop and simplify the error message. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 19 +++++-------------- .../machine-loadparm-s390-char-invalid.err | 2 +- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c542782750..b1cc229d97 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6298,8 +6298,6 @@ virDomainObjCheckActive(virDomainObj *dom) static bool virDomainDeviceLoadparmIsValid(const char *loadparm) { - size_t i; - if (virStringIsEmpty(loadparm) || !STRLIM(loadparm, 8)) { virReportError(VIR_ERR_INTERNAL_ERROR, _("loadparm value '%s' must be between 1 and 8 char= acters"), @@ -6307,18 +6305,11 @@ virDomainDeviceLoadparmIsValid(const char *loadparm) return false; } - for (i =3D 0; i < strlen(loadparm); i++) { - uint8_t c =3D loadparm[i]; - - if (('A' <=3D c && c <=3D 'Z') || ('0' <=3D c && c <=3D '9') || - (c =3D=3D '.') || (c =3D=3D ' ')) { - continue; - } else { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid loadparm char '%c', expecting chars" - " in set of [a-zA-Z0-9.] and blank spaces"), = c); - return false; - } + if (strspn(loadparm, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv= wxyz0123456789. ") !=3D strlen(loadparm)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid loadparm value '%s', expecting chars in = set of [a-zA-Z0-9.] and blank spaces"), + loadparm); + return false; } return true; diff --git a/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err = b/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err index c3eb455594..0283db9f48 100644 --- a/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err +++ b/tests/qemuxml2argvdata/machine-loadparm-s390-char-invalid.err @@ -1 +1 @@ -internal error: invalid loadparm char '?', expecting chars in set of [a-zA= -Z0-9.] and blank spaces +internal error: invalid loadparm value 'SYS1?', expecting chars in set of = [a-zA-Z0-9.] and blank spaces --=20 2.31.1 From nobody Fri Apr 19 18:29:52 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=1637845205; cv=none; d=zohomail.com; s=zohoarc; b=ic0ZTcH/zLjWxmcvpgNPD8k/1iWsbNdRBlBGH2NVrgKKfadvZcR7bx47K93qthsPoeCCfQ2TG+URrQnuCTv8VUm+s/LIz9NMGsuRKysfvgSQ3yUhnNObr9uZaxqldx8WS2wpMBwk/8Rk2ZFHdaqMlmnsGLd1pTvTU3QEhv6BIP0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637845205; 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=6VW26yURppcgGXDTTa4Ksz2eh/FDui42c3VWcVeOWIQ=; b=FG7VWcev1r6SFJVAxCodJ54kChqUj27DtCwui8jPib4Jp7RkwACR/vQMJ+mYal58keM538ZORSCZAbbejlnytPvCsYTI9ApEFcGHTkCEe9pLhLnAxoNY7NPXjNfOwGWtHiGaKkWDUxaz0Qa3QSpUB++EtLfeQ1q09eWdisp6KUE= 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 1637845205923924.5919233074945; Thu, 25 Nov 2021 05:00:05 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-576-X3apCdpGNzq5rXwYIWeMHA-1; Thu, 25 Nov 2021 07:59:37 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C0E67DC58; Thu, 25 Nov 2021 12:59:32 +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 A3B4310114AE; Thu, 25 Nov 2021 12:59:32 +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 780FE1809CB9; Thu, 25 Nov 2021 12:59:32 +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 1APCxKhs031026 for ; Thu, 25 Nov 2021 07:59:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id 11DE45D740; Thu, 25 Nov 2021 12:59:20 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61EFB54461 for ; Thu, 25 Nov 2021 12:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637845204; 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=6VW26yURppcgGXDTTa4Ksz2eh/FDui42c3VWcVeOWIQ=; b=BVNYK0VRVR5Fqjwvyuwc9vAqAo8PolqroxMm+LPaeqGlI3KGYnSnRS4CoPAGcYfhxxXkNr hW2P+gJ569I9Behfqjh85FIhpBwaETzL6xT5W6GV2wSSSyUzNviU95laVTbaSGpw1LEE7o YA0vjURnBjzAQT18/oF3K1Z/M8SOofY= X-MC-Unique: X3apCdpGNzq5rXwYIWeMHA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/6] conf: domain: Convert all string length checks to STRLIM Date: Thu, 25 Nov 2021 13:59:11 +0100 Message-Id: <04e319dfdc5d792d51f6e406a8994947e9fdfd8a.1637845012.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.84 on 10.5.11.22 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) X-ZM-MESSAGEID: 1637845209407100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b1cc229d97..2e88526eb4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7791,7 +7791,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, g_autoptr(virSecurityLabelDef) seclabel =3D NULL; if ((model =3D virXMLPropString(ctxt->node, "model")) && - strlen(model) >=3D VIR_SECURITY_MODEL_BUFLEN - 1) + !STRLIM(model, VIR_SECURITY_MODEL_BUFLEN - 1)) g_clear_pointer(&model, g_free); if (!(seclabel =3D virSecurityLabelDefNew(model))) @@ -7856,8 +7856,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && seclabel->type !=3D VIR_DOMAIN_SECLABEL_NONE)) { seclabel->label =3D virXPathString("string(./label[1])", ctxt); - if (!seclabel->label || - strlen(seclabel->label) >=3D VIR_SECURITY_LABEL_BUFLEN - 1) { + if (!seclabel->label || !STRLIM(seclabel->label, VIR_SECURITY_LABE= L_BUFLEN - 1)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("security label is missing")); return NULL; @@ -7870,8 +7869,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->type !=3D VIR_DOMAIN_SECLABEL_NONE)) { seclabel->imagelabel =3D virXPathString("string(./imagelabel[1])",= ctxt); - if (!seclabel->imagelabel || - strlen(seclabel->imagelabel) >=3D VIR_SECURITY_LABEL_BUFLEN - = 1) { + if (!seclabel->imagelabel || !STRLIM(seclabel->imagelabel, VIR_SEC= URITY_LABEL_BUFLEN - 1)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("security imagelabel is missing")); return NULL; @@ -7883,7 +7881,7 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, seclabel->baselabel =3D virXPathString("string(./baselabel[1])", c= txt); if (seclabel->baselabel && - strlen(seclabel->baselabel) >=3D VIR_SECURITY_LABEL_BUFLEN - 1) + !STRLIM(seclabel->baselabel, VIR_SECURITY_LABEL_BUFLEN - 1)) g_clear_pointer(&seclabel->baselabel, g_free); } @@ -8047,7 +8045,7 @@ virSecurityDeviceLabelDefParseXML(virSecurityDeviceLa= belDef ***seclabels_rtn, ctxt->node =3D list[i]; label =3D virXPathString("string(./label)", ctxt); - if (label && strlen(label) < VIR_SECURITY_LABEL_BUFLEN) + if (label && STRLIM(label, VIR_SECURITY_LABEL_BUFLEN - 1)) seclabels[i]->label =3D g_steal_pointer(&label); if (seclabels[i]->label && !seclabels[i]->relabel) { @@ -17508,7 +17506,7 @@ virDomainFeaturesHyperVDefParse(virDomainDef *def, return -1; } - if (strlen(def->hyperv_vendor_id) > VIR_DOMAIN_HYPERV_VENDOR_I= D_MAX) { + if (!STRLIM(def->hyperv_vendor_id, VIR_DOMAIN_HYPERV_VENDOR_ID= _MAX)) { virReportError(VIR_ERR_XML_ERROR, _("HyperV vendor_id value must not be more = than %d characters."), VIR_DOMAIN_HYPERV_VENDOR_ID_MAX); --=20 2.31.1