From nobody Fri Nov 14 05:14:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584563148; cv=none; d=zohomail.com; s=zohoarc; b=g+g37a6nkhJ+aYBYI8zsBdNZx8RWqjaMj/jPmUpeJPMazhGF4Var1vp6pPYiy4+ZjB1ukQupyYFeYjb19zzKiylOHCmso1ST1WwELQH2JbuEWPRpyCrmCTBH0/ZxARq/qd7TsWEz2Ax4Vgk+BKVQoxdZwaOdUTSuVaXQpq+LDT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584563148; 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=ahENl3BNbjiX9217T8D2HNUwmfnYsYvdtYYCuVYsDWw=; b=iKWZMg6Pl+7oicIaJmGmadwwQmiGEYPaRZUiEOQJYxj4ZhtqUu3/ZtP0XFjZqd/LH3NoaEYXlDCS7bvxEKvorHySgeu7yuOGxZWZmA7a4AlhXK9BnuTmiCnJxAA1lAq968oh9FpJ1n0GGF7Bn2pJf3kl1xhJAU1dEG+HZ7A6ZCI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584563148496559.068917345743; Wed, 18 Mar 2020 13:25:48 -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-47-VhdF9y2RNTGDx6XBohCSyQ-1; Wed, 18 Mar 2020 16:25:44 -0400 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 D71E4100550E; Wed, 18 Mar 2020 20:25:38 +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 6BE1660BFB; Wed, 18 Mar 2020 20:25:38 +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 9D35318089CF; Wed, 18 Mar 2020 20:25:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IKOmXF004609 for ; Wed, 18 Mar 2020 16:24:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38E8360C84; Wed, 18 Mar 2020 20:24:48 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id C94C7610B0; Wed, 18 Mar 2020 20:24:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584563147; 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=ahENl3BNbjiX9217T8D2HNUwmfnYsYvdtYYCuVYsDWw=; b=E0nfQoll2g4sKB8tq0XF0ZpFv5Qy1PSLkGPIimG4bvNytIlxI/U+Uhg4cUs0+6GvCv7Hqw FHTsYXibUGFMfEwztXTpck7FSiEHULaZIBXhiqF16ek91BGwl5X6JdG9cbXc43Dqx8Rb3r H20TE2U2ffjXhTo3n5lRW6E/503uAQc= X-MC-Unique: VhdF9y2RNTGDx6XBohCSyQ-1 From: John Snow To: qemu-devel@nongnu.org, jsnow@redhat.com, Peter Maydell Subject: [PULL v2 02/11] hbitmap: assert that we don't create bitmap larger than INT64_MAX Date: Wed, 18 Mar 2020 16:23:32 -0400 Message-Id: <20200318202341.6961-3-jsnow@redhat.com> In-Reply-To: <20200318202341.6961-1-jsnow@redhat.com> References: <20200318202341.6961-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, Max Reitz , Stefan Hajnoczi , "Dr. David Alan Gilbert" 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 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" From: Vladimir Sementsov-Ogievskiy We have APIs which returns signed int64_t, to be able to return error. Therefore we can't handle bitmaps with absolute size larger than (INT64_MAX+1). Still, keep maximum to be INT64_MAX which is a bit safer. Note, that bitmaps are used to represent disk images, which can't exceed INT64_MAX anyway. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: John Snow Message-id: 20200205112041.6003-2-vsementsov@virtuozzo.com Signed-off-by: John Snow --- util/hbitmap.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/util/hbitmap.c b/util/hbitmap.c index 242c6e519c..7f9b3e0cd7 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -716,6 +716,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) HBitmap *hb =3D g_new0(struct HBitmap, 1); unsigned i; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 assert(granularity >=3D 0 && granularity < 64); @@ -746,6 +747,7 @@ void hbitmap_truncate(HBitmap *hb, uint64_t size) uint64_t num_elements =3D size; uint64_t old; =20 + assert(size <=3D INT64_MAX); hb->orig_size =3D size; =20 /* Size comes in as logical elements, adjust for granularity. */ --=20 2.21.1