From nobody Wed May 14 13:59:11 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1523630862399163.6632581830895; Fri, 13 Apr 2018 07:47:42 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 197F93134C6C; Fri, 13 Apr 2018 14:47:41 +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 DF3AC90C3A; Fri, 13 Apr 2018 14:47:40 +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 A6264B3498; Fri, 13 Apr 2018 14:47:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w3DElO8h012366 for ; Fri, 13 Apr 2018 10:47:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 385522026E0E; Fri, 13 Apr 2018 14:47:24 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id D401F2026DFD for ; Fri, 13 Apr 2018 14:47:23 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 13 Apr 2018 16:47:15 +0200 Message-Id: <0b16967cd2ba4a1d5a9f1e3d1076425ce5b5587e.1523630758.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 8/9] virobject: Check if @parent is the first member in class 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 13 Apr 2018 14:47:41 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Our virObject code relies heavily on the fact that the first member of the class struct is type of virObject (or some derivation of if). Let's check for that. Signed-off-by: Michal Privoznik Reviewed-by: Erik Skultety --- src/util/virobject.c | 31 +++++++++++++++++++++---------- src/util/virobject.h | 5 ++++- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/util/virobject.c b/src/util/virobject.c index c5a98d21cc..e184f5349e 100644 --- a/src/util/virobject.c +++ b/src/util/virobject.c @@ -77,6 +77,7 @@ virObjectOnceInit(void) { if (!(virObjectClass =3D virClassNew(NULL, "virObject", + 0, sizeof(virObject), NULL))) return -1; @@ -159,21 +160,31 @@ virClassForObjectRWLockable(void) virClassPtr virClassNew(virClassPtr parent, const char *name, + size_t off, size_t objectSize, virObjectDisposeCallback dispose) { virClassPtr klass; =20 - if (parent =3D=3D NULL && - STRNEQ(name, "virObject")) { - virReportInvalidNonNullArg(parent); - return NULL; - } else if (parent && - objectSize <=3D parent->objectSize) { - virReportInvalidArg(objectSize, - _("object size %zu of %s is smaller than paren= t class %zu"), - objectSize, name, parent->objectSize); - return NULL; + if (parent =3D=3D NULL) { + if (STRNEQ(name, "virObject")) { + virReportInvalidNonNullArg(parent); + return NULL; + } + } else { + if (objectSize <=3D parent->objectSize) { + virReportInvalidArg(objectSize, + _("object size %zu of %s is smaller than p= arent class %zu"), + objectSize, name, parent->objectSize); + return NULL; + } + + if (off) { + virReportInvalidArg(off, + _("struct %s doesn't have 'parent' as its = first member"), + name); + return NULL; + } } =20 if (VIR_ALLOC(klass) < 0) diff --git a/src/util/virobject.h b/src/util/virobject.h index 92dd512399..25db3a0c22 100644 --- a/src/util/virobject.h +++ b/src/util/virobject.h @@ -76,11 +76,14 @@ virClassPtr virClassForObjectRWLockable(void); # endif =20 # define VIR_CLASS_NEW(prnt, name) \ - virClassNew(prnt, #name, sizeof(name), name##Dispose) + virClassNew(prnt, #name, \ + offsetof(name, parent), \ + sizeof(name), name##Dispose) =20 virClassPtr virClassNew(virClassPtr parent, const char *name, + size_t off, size_t objectSize, virObjectDisposeCallback dispose) VIR_PARENT_REQUIRED ATTRIBUTE_NONNULL(2); --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list