From nobody Mon Feb 9 07:38:20 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=1681907009; cv=none; d=zohomail.com; s=zohoarc; b=CfAZqp0NsoUUcQQMPE96K1XeU6Hto/DZLlRcPkJjfwEZsbWgYfYte/JDoxu3DTJsA36y+Z5w+Rl0JleKr565PA/EDBgtKb5cbVbZs4s7h4twW4FWBteuaktcnLbPwTTJIgmhaB0p/ERvlI1D6XYDkBdX2B82udS1qBNOGtGPX5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681907009; 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=sZe3+zfRj7PdYFnIs/iu+kQzdKR8viCEYluwUDZqBig=; b=ISsDrQ4hM2YpP21gh4SrIxjrpdKfo4n54HHqWT1yP9vDhXQhnhwIqRsTE9u+QPQ8i1Cl6d21Fuei+T8b7if1JyH5Jw4zGTKc0mv87vcXwhCToI8+0rvF6aoMV71dEzZxuGKqfANcVjMek/uEKkT/uv7X3LTXycDmIpsSvEdiPGA= 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 1681907009775621.9333786289335; Wed, 19 Apr 2023 05:23:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-608-5jwkhvK8O4u-2Hi5eivhaA-1; Wed, 19 Apr 2023 08:23:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DD5D4101A551; Wed, 19 Apr 2023 12:23:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C845751E3; Wed, 19 Apr 2023 12:23:23 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id AAFD919465B2; Wed, 19 Apr 2023 12:23:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id BF75C19465B7 for ; Wed, 19 Apr 2023 12:04:49 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id DDD9B492B10; Wed, 19 Apr 2023 12:04:47 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6025A492B07 for ; Wed, 19 Apr 2023 12:04:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681907008; 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=sZe3+zfRj7PdYFnIs/iu+kQzdKR8viCEYluwUDZqBig=; b=LuSzkSpuI5+OZknNbTWxFMu+mUrvuKrnsWJlhRKQ5pPBRvFDPZjFY3Lh5VDFl4DJC9w1xP 719JywipLA1I4fMkdL0xSvTXimjmmCjtrecmwSEtAVp2hR7lEb7cmaDpScfUAiiMHJbWgf GcszxjHDBE9YsbIY1PpOD7JXgst1I+8= X-MC-Unique: 5jwkhvK8O4u-2Hi5eivhaA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v3 04/25] virTypedParameterAssignValueVArgs: Ensure proper typed param type in caller Date: Wed, 19 Apr 2023 14:04:21 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1681907010969100001 Content-Type: text/plain; charset="utf-8" There are two callers of virTypedParameterAssignValueVArgs. - 'virTypedParameterAssignValue' always uses the correct type, thus doesn't need to be modified. Just use the proper type in the function declaration - 'virTypedParameterAssign' can get improper type, but we can move the validation into it decreasing the scope in which failures need to be propagated. Signed-off-by: Peter Krempa Reviewed-by: Martin Kletzander --- src/util/virtypedparam.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/util/virtypedparam.c b/src/util/virtypedparam.c index fe4c04bcea..f325f3b012 100644 --- a/src/util/virtypedparam.c +++ b/src/util/virtypedparam.c @@ -203,7 +203,7 @@ virTypedParameterToString(virTypedParameterPtr param) } -static int +static void virTypedParameterAssignValueVArgs(virTypedParameterPtr param, virTypedParameterType type, va_list ap, @@ -240,30 +240,23 @@ virTypedParameterAssignValueVArgs(virTypedParameterPt= r param, param->value.s =3D g_strdup(""); break; case VIR_TYPED_PARAM_LAST: - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected type %1$d for field %2$s"), type, - NULLSTR(param->field)); - return -1; + break; } - - return 0; } static int virTypedParameterAssignValue(virTypedParameterPtr param, - int type, + virTypedParameterType type, ...) { - int ret; va_list ap; va_start(ap, type); - ret =3D virTypedParameterAssignValueVArgs(param, type, ap, true); + virTypedParameterAssignValueVArgs(param, type, ap, true); va_end(ap); - return ret; + return 0; } @@ -276,7 +269,6 @@ virTypedParameterAssign(virTypedParameterPtr param, con= st char *name, int type, ...) { va_list ap; - int ret =3D -1; if (virStrcpyStatic(param->field, name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Field name '%1$s' too lo= ng"), @@ -284,11 +276,18 @@ virTypedParameterAssign(virTypedParameterPtr param, c= onst char *name, return -1; } + if (type < VIR_TYPED_PARAM_INT || + type >=3D VIR_TYPED_PARAM_LAST) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected type %1$d for field %2$s"), type, nam= e); + return -1; + } + va_start(ap, type); - ret =3D virTypedParameterAssignValueVArgs(param, type, ap, false); + virTypedParameterAssignValueVArgs(param, type, ap, false); va_end(ap); - return ret; + return 0; } --=20 2.39.2