From nobody Mon Feb 9 19:44:10 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=1669122197; cv=none; d=zohomail.com; s=zohoarc; b=g6txWhiA2AGwUR1KPSYw8DwRnWEqCq/mYdrNHH5O1f8JZWOGI3iPzJ0Gf2Stzk4WVHgLG0phl9o/iUaatqNx4KgC3xbMJIpxSU6YHvmfPJ1CAfn0iyIk8YQvWYnSpS9CWat8E0crEOttKlS8gGm6ho/ECBZPZoaanRJiJ0CkfqQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669122197; 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=flwiqerZgNtnkbYjzd5gdFnM65UNFBSEAwZMurFAD64=; b=RKoOYfV8ePBx8RDYulaKT1UbQ/Q9nrhLVZ8kwPw3oEIYqjqDp+JGTrCGRh+1S2EX/knJWEYU7FQJtZbq/Ka2Phc9dkJUXl8lT6FmVSgDXFXfwhNrMn5H1W4PA1QwQeVAsHJBQYQ6cOymWFBLESioO9AZLa0FTZ35z4mkXzS4sqg= 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 1669122197976977.613350547047; Tue, 22 Nov 2022 05:03:17 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-GxVWEm15MECmp1jv5LxYsg-1; Tue, 22 Nov 2022 08:03:13 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0286C3C01DE3; Tue, 22 Nov 2022 13:03:10 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E4362140EBF3; Tue, 22 Nov 2022 13:03:09 +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 C75331946589; Tue, 22 Nov 2022 13:03:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 59E3C1946587 for ; Tue, 22 Nov 2022 13:03:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3ACCF492B2C; Tue, 22 Nov 2022 13:03:07 +0000 (UTC) Received: from speedmetal.redhat.com (ovpn-208-20.brq.redhat.com [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0A8D492B2A for ; Tue, 22 Nov 2022 13:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669122197; 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=flwiqerZgNtnkbYjzd5gdFnM65UNFBSEAwZMurFAD64=; b=JrK/mmbR560phq4fjWKt3btw4KoPlRnzq3cPPJOZqBUAkLUMQ3P+ahLCgguQBwtX0uGd5o LVqMWHg+vlUH+OCUh1+0qfzEKxKFB47A9QyA8vKIpZpVrIGnqn0KuMhSZ+0RS7iIgLnP5p YK73eacOGJXzloCUJJ6VlhtyGmATJXo= X-MC-Unique: GxVWEm15MECmp1jv5LxYsg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] internal: Refuse values exceeding range of 'unsigned int' in virCheckFlags Date: Tue, 22 Nov 2022 14:02:54 +0100 Message-Id: <94b5d762ffea808ad59955c62a0ff0c1a9c11561.1669122136.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 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.7 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: 1669122198796100001 Content-Type: text/plain; charset="utf-8" Historically our migration APIs declare 'unsigned long flags'. Since it's baked into our API we can't change that but we can avoid compatibility problems by preemptively refusing the extra range on certain arches to prevent future surprise. Modify the macro to verify that value passed inside 'flags' doesn't exceed the range of 'unsigned int'. Signed-off-by: Peter Krempa --- src/internal.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/internal.h b/src/internal.h index 35cc22ee3d..9dc34a0bf5 100644 --- a/src/internal.h +++ b/src/internal.h @@ -269,10 +269,17 @@ */ #define virCheckFlags(supported, retval) \ do { \ - unsigned long __unsuppflags =3D flags & ~(supported); \ + unsigned int __uiflags =3D flags; \ + unsigned int __unsuppflags =3D flags & ~(supported); \ + if (__uiflags !=3D flags) { \ + virReportInvalidArg(flags, \ + _("unsupported use of long flags in functi= on %s"), \ + __FUNCTION__); \ + return retval; \ + } \ if (__unsuppflags) { \ virReportInvalidArg(flags, \ - _("unsupported flags (0x%lx) in function %= s"), \ + _("unsupported flags (0x%x) in function %s= "), \ __unsuppflags, __FUNCTION__); \ return retval; \ } \ @@ -291,10 +298,17 @@ */ #define virCheckFlagsGoto(supported, label) \ do { \ - unsigned long __unsuppflags =3D flags & ~(supported); \ + unsigned int __uiflags =3D flags; \ + unsigned int __unsuppflags =3D flags & ~(supported); \ + if (__uiflags !=3D flags) { \ + virReportInvalidArg(flags, \ + _("unsupported use of long flags in functi= on %s"), \ + __FUNCTION__); \ + goto label; \ + } \ if (__unsuppflags) { \ virReportInvalidArg(flags, \ - _("unsupported flags (0x%lx) in function %= s"), \ + _("unsupported flags (0x%x) in function %s= "), \ __unsuppflags, __FUNCTION__); \ goto label; \ } \ --=20 2.37.3