summaryrefslogtreecommitdiff
path: root/pkg/nsd/patch/0003-Avoid-pointer-arithmetic-on-void.patch
blob: dfd635b6be149534ebaf43bcd159886c4b40b14a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
From fcfbed8db1c746bd938ac6a548036af95b678341 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
Date: Sun, 16 Jun 2019 23:17:47 -0700
Subject: [PATCH] Avoid pointer arithmetic on `void *`

The pointer operand to the binary `+` operator must be to a complete
object type.
---
 dbaccess.c         |  8 ++++----
 difffile.c         |  4 ++--
 region-allocator.c |  4 ++--
 udb.c              | 12 ++++++------
 udb.h              |  4 ++--
 xfrd.c             |  2 +-
 6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/dbaccess.c b/dbaccess.c
index da0762e9..87f75f9c 100644
--- a/dbaccess.c
+++ b/dbaccess.c
@@ -210,19 +210,19 @@ static void read_zone_recurse(udb_base* udb, namedb_type* db,
 		/* pre-order process of node->elem, for radix tree this is
 		 * also in-order processing (identical to order tree_next()) */
 		read_node_elem(udb, db, dname_region, zone, (struct domain_d*)
-			(udb->base + node->elem.data));
+			((char*)udb->base + node->elem.data));
 	}
 	if(node->lookup.data) {
 		uint16_t i;
 		struct udb_radarray_d* a = (struct udb_radarray_d*)
-			(udb->base + node->lookup.data);
+			((char*)udb->base + node->lookup.data);
 		/* we do not care for what the exact radix key is, we want
 		 * to add all of them and the read routine does not need
 		 * the radix-key, it has it stored */
 		for(i=0; i<a->len; i++) {
 			if(a->array[i].node.data) {
 				read_zone_recurse(udb, db, dname_region, zone,
-					(struct udb_radnode_d*)(udb->base +
+					(struct udb_radnode_d*)((char*)udb->base +
 						a->array[i].node.data));
 			}
 		}
@@ -240,7 +240,7 @@ read_zone_data(udb_base* udb, namedb_type* db, region_type* dname_region,
 	if(RADTREE(&dtree)->root.data)
 		read_zone_recurse(udb, db, dname_region, zone,
 			(struct udb_radnode_d*)
-			(udb->base + RADTREE(&dtree)->root.data));
+			((char*)udb->base + RADTREE(&dtree)->root.data));
 	udb_ptr_unlink(&dtree, udb);
 }
 
diff --git a/difffile.c b/difffile.c
index b3aee0b4..82056ada 100644
--- a/difffile.c
+++ b/difffile.c
@@ -1631,7 +1631,7 @@ void* task_new_stat_info(udb_base* udb, udb_ptr* last, struct nsdst* stat,
 	p = TASKLIST(&e)->zname;
 	memcpy(p, stat, sizeof(*stat));
 	udb_ptr_unlink(&e, udb);
-	return p + sizeof(*stat);
+	return (char*)p + sizeof(*stat);
 }
 #endif /* BIND8_STATS */
 
@@ -1653,7 +1653,7 @@ task_new_add_zone(udb_base* udb, udb_ptr* last, const char* zone,
 	TASKLIST(&e)->yesno = zonestatid;
 	p = TASKLIST(&e)->zname;
 	memcpy(p, zone, zlen+1);
-	memmove(p+zlen+1, pattern, plen+1);
+	memmove((char*)p+zlen+1, pattern, plen+1);
 	udb_ptr_unlink(&e, udb);
 }
 
diff --git a/region-allocator.c b/region-allocator.c
index 638c861b..f53841ad 100644
--- a/region-allocator.c
+++ b/region-allocator.c
@@ -272,7 +272,7 @@ region_alloc(region_type *region, size_t size)
 		region->total_allocated += size;
 		++region->large_objects;
 
-		return result + sizeof(struct large_elem);
+		return (char *)result + sizeof(struct large_elem);
 	}
 
 	if (region->recycle_bin && region->recycle_bin[aligned_size]) {
@@ -469,7 +469,7 @@ region_recycle(region_type *region, void *block, size_t size)
 		region->total_allocated -= size;
 		--region->large_objects;
 
-		l = (struct large_elem*)(block-sizeof(struct large_elem));
+		l = (struct large_elem*)((char*)block-sizeof(struct large_elem));
 		if(l->prev)
 			l->prev->next = l->next;
 		else	region->large_list = l->next;
diff --git a/udb.c b/udb.c
index 1b41ab91..b02a482b 100644
--- a/udb.c
+++ b/udb.c
@@ -192,13 +192,13 @@ udb_base_create_fd(const char* fname, int fd, udb_walk_relptr_func walkfunc,
 	}
 
 	/* init completion */
-	udb->glob_data = (udb_glob_d*)(udb->base+sizeof(uint64_t));
+	udb->glob_data = (udb_glob_d*)((char*)udb->base+sizeof(uint64_t));
 	r = 0;
 	/* cannot be dirty because that is goto fail above */
 	if(udb->glob_data->dirty_alloc != udb_dirty_clean)
 		r = 1;
 	udb->alloc = udb_alloc_create(udb, (udb_alloc_d*)(
-		(void*)udb->glob_data+sizeof(*udb->glob_data)));
+		(char*)udb->glob_data+sizeof(*udb->glob_data)));
 	if(!udb->alloc) {
 		log_msg(LOG_ERR, "out of memory");
 		udb_base_free(udb);
@@ -555,10 +555,10 @@ udb_base_remap(udb_base* udb, udb_alloc* alloc, uint64_t nsize)
 		/* fix up realpointers in udb and alloc */
 		/* but mremap may have been nice and not move the base */
 		udb->base = nb;
-		udb->glob_data = (udb_glob_d*)(nb+sizeof(uint64_t));
+		udb->glob_data = (udb_glob_d*)((char*)nb+sizeof(uint64_t));
 		/* use passed alloc pointer because the udb->alloc may not
 		 * be initialized yet */
-		alloc->disk = (udb_alloc_d*)((void*)udb->glob_data
+		alloc->disk = (udb_alloc_d*)((char*)udb->glob_data
 			+sizeof(*udb->glob_data));
 	}
 	udb->base_size = nsize;
@@ -798,7 +798,7 @@ regen_ptrlist(void* base, udb_base* udb, udb_alloc* alloc,
 		if(exp == UDB_EXP_XL) {
 			assert(at != rb_old); /* should have been freed */
 			regen_its_ptrs(base, udb, atp,
-				((void*)atp)+sizeof(udb_xl_chunk_d),
+				((char*)atp)+sizeof(udb_xl_chunk_d),
 				sz-sizeof(udb_xl_chunk_d) - sizeof(uint64_t)*2,
 				rb_old, rb_new);
 			at += sz;
@@ -807,7 +807,7 @@ regen_ptrlist(void* base, udb_base* udb, udb_alloc* alloc,
 		} else { /* data chunk */
 			assert(at != rb_old); /* should have been freed */
 			regen_its_ptrs(base, udb, atp,
-				((void*)atp)+sizeof(udb_chunk_d),
+				((char*)atp)+sizeof(udb_chunk_d),
 				sz-sizeof(udb_chunk_d)-1, rb_old, rb_new);
 			at += sz;
 		}
diff --git a/udb.h b/udb.h
index 8d7ee137..3ee98648 100644
--- a/udb.h
+++ b/udb.h
@@ -52,9 +52,9 @@ typedef struct udb_alloc udb_alloc;
 typedef uint64_t udb_void;
 
 /** convert relptr to usable pointer */
-#define UDB_REL(base, relptr) ((base) + (relptr))
+#define UDB_REL(base, relptr) ((void*)((char*)(base) + (relptr)))
 /** from system pointer to relative pointer */
-#define UDB_SYSTOREL(base, ptr) ((udb_void)((void*)(ptr) - (base)))
+#define UDB_SYSTOREL(base, ptr) ((udb_void)((char*)(ptr) - (char*)(base)))
 
 /** MAX 2**x exponent of alloced chunks, for 1Mbytes.  The smallest
  * chunk is 16bytes (8preamble+8data), so 0-3 is unused. */
diff --git a/xfrd.c b/xfrd.c
index 3865747a..89713236 100644
--- a/xfrd.c
+++ b/xfrd.c
@@ -2465,7 +2465,7 @@ static void
 xfrd_process_stat_info_task(xfrd_state_type* xfrd, struct task_list_d* task)
 {
 	size_t i;
-	stc_type* p = (void*)task->zname + sizeof(struct nsdst);
+	stc_type* p = (void*)((char*)task->zname + sizeof(struct nsdst));
 	stats_add(&xfrd->nsd->st, (struct nsdst*)task->zname);
 	for(i=0; i<xfrd->nsd->child_count; i++) {
 		xfrd->nsd->children[i].query_count += *p++;
-- 
2.23.0