From: Ondřej Surý Date: Wed, 17 Dec 2025 09:01:06 +0000 (+0100) Subject: Use offsetof() instead of pointer arithmetics to get slabheader X-Git-Tag: v9.21.19~22^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8e07a0b5aed51828af72af2a8d58b090088725d;p=thirdparty%2Fbind9.git Use offsetof() instead of pointer arithmetics to get slabheader In rdataset_getheader() a cast of the raw buffer to dns_slabheader_t and pointer arithmetics was used to get the start of the slabheader structure. Use more correct offsetof(dns_slabheader_t, raw) to calculate the correct start of the dns_slabheader_t from the flexible member raw[]. --- diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c index c56cd3b03bc..64e955cad4e 100644 --- a/lib/dns/rdataslab.c +++ b/lib/dns/rdataslab.c @@ -801,8 +801,8 @@ rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) { static dns_slabheader_t * rdataset_getheader(const dns_rdataset_t *rdataset) { - dns_slabheader_t *header = (dns_slabheader_t *)rdataset->slab.raw; - return header - 1; + uint8_t *rawbuf = rdataset->slab.raw; + return (dns_slabheader_t *)(rawbuf - offsetof(dns_slabheader_t, raw)); } dns_slabtop_t *