Files
oasis-linux-mirror/pkg/nsd/patch/0003-Avoid-pointer-arithmetic-on-void.patch
T
2019-06-17 00:05:52 -07:00

180 lines
6.4 KiB
Diff

From 832067946e71d1d09e47beb328c70f56c097adeb 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 c2eeff8a..2d261089 100644
--- a/xfrd.c
+++ b/xfrd.c
@@ -2455,7 +2455,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.20.1