[PATCH libnftnl 4/4] src: Use memcpy() to handle potentially unaligned data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Rolf Eike Beer <eike@xxxxxxxxxx> reported that nft-expr_quota-test fails
with a SIGBUS on SPARC due to unaligned accesses. This patch resolves
that and fixes additional sources of unaligned accesses matching the
same pattern. Both nft-expr_quota-test and nft-expr_objref-test
generated unaligned accesses on DEC Alpha.

Bug: https://bugs.gentoo.org/666448
Signed-off-by: Matt Turner <mattst88@xxxxxxxxx>
---
 src/chain.c          | 12 ++++++------
 src/expr/bitwise.c   |  6 +++---
 src/expr/byteorder.c | 10 +++++-----
 src/expr/cmp.c       |  4 ++--
 src/expr/connlimit.c |  4 ++--
 src/expr/counter.c   |  4 ++--
 src/expr/ct.c        |  8 ++++----
 src/expr/dup.c       |  4 ++--
 src/expr/dynset.c    | 10 +++++-----
 src/expr/exthdr.c    | 14 +++++++-------
 src/expr/fib.c       |  6 +++---
 src/expr/fwd.c       |  6 +++---
 src/expr/hash.c      | 16 ++++++++--------
 src/expr/immediate.c |  4 ++--
 src/expr/limit.c     | 10 +++++-----
 src/expr/log.c       | 10 +++++-----
 src/expr/lookup.c    |  8 ++++----
 src/expr/masq.c      |  6 +++---
 src/expr/match.c     |  2 +-
 src/expr/meta.c      |  6 +++---
 src/expr/nat.c       | 14 +++++++-------
 src/expr/numgen.c    | 10 +++++-----
 src/expr/objref.c    |  6 +++---
 src/expr/osf.c       |  4 ++--
 src/expr/payload.c   | 16 ++++++++--------
 src/expr/queue.c     |  8 ++++----
 src/expr/quota.c     |  6 +++---
 src/expr/range.c     |  4 ++--
 src/expr/redir.c     |  6 +++---
 src/expr/reject.c    |  4 ++--
 src/expr/rt.c        |  4 ++--
 src/expr/socket.c    |  4 ++--
 src/expr/target.c    |  2 +-
 src/expr/tproxy.c    |  6 +++---
 src/expr/tunnel.c    |  4 ++--
 src/expr/xfrm.c      |  8 ++++----
 src/gen.c            |  2 +-
 src/obj/counter.c    |  4 ++--
 src/obj/ct_helper.c  |  4 ++--
 src/obj/ct_timeout.c |  4 ++--
 src/obj/limit.c      | 10 +++++-----
 src/obj/quota.c      |  6 +++---
 src/obj/tunnel.c     | 28 ++++++++++++++--------------
 src/object.c         |  6 +++---
 src/rule.c           | 12 ++++++------
 src/set.c            | 26 +++++++++++++-------------
 src/set_elem.c       | 12 +++++++-----
 src/table.c          |  8 ++++----
 src/utils.c          |  4 ++--
 49 files changed, 192 insertions(+), 190 deletions(-)

diff --git a/src/chain.c b/src/chain.c
index 06252b6..01d62c8 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -190,22 +190,22 @@ int nftnl_chain_set_data(struct nftnl_chain *c, uint16_t attr,
 		memcpy(&c->prio, data, sizeof(c->prio));
 		break;
 	case NFTNL_CHAIN_POLICY:
-		c->policy = *((uint32_t *)data);
+		memcpy(&c->policy, data, sizeof(c->policy));
 		break;
 	case NFTNL_CHAIN_USE:
-		c->use = *((uint32_t *)data);
+		memcpy(&c->use, data, sizeof(c->use));
 		break;
 	case NFTNL_CHAIN_BYTES:
-		c->bytes = *((uint64_t *)data);
+		memcpy(&c->bytes, data, sizeof(c->bytes));
 		break;
 	case NFTNL_CHAIN_PACKETS:
-		c->packets = *((uint64_t *)data);
+		memcpy(&c->packets, data, sizeof(c->packets));
 		break;
 	case NFTNL_CHAIN_HANDLE:
-		c->handle = *((uint64_t *)data);
+		memcpy(&c->handle, data, sizeof(c->handle));
 		break;
 	case NFTNL_CHAIN_FAMILY:
-		c->family = *((uint32_t *)data);
+		memcpy(&c->family, data, sizeof(c->family));
 		break;
 	case NFTNL_CHAIN_TYPE:
 		if (c->flags & (1 << NFTNL_CHAIN_TYPE))
diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
index ebfbcd0..79d6a51 100644
--- a/src/expr/bitwise.c
+++ b/src/expr/bitwise.c
@@ -37,13 +37,13 @@ nftnl_expr_bitwise_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_BITWISE_SREG:
-		bitwise->sreg = *((uint32_t *)data);
+		memcpy(&bitwise->sreg, data, sizeof(bitwise->sreg));
 		break;
 	case NFTNL_EXPR_BITWISE_DREG:
-		bitwise->dreg = *((uint32_t *)data);
+		memcpy(&bitwise->dreg, data, sizeof(bitwise->dreg));
 		break;
 	case NFTNL_EXPR_BITWISE_LEN:
-		bitwise->len = *((unsigned int *)data);
+		memcpy(&bitwise->len, data, sizeof(bitwise->len));
 		break;
 	case NFTNL_EXPR_BITWISE_MASK:
 		memcpy(&bitwise->mask.val, data, data_len);
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index 4cddd4a..35c1450 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -37,19 +37,19 @@ nftnl_expr_byteorder_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_BYTEORDER_SREG:
-		byteorder->sreg = *((uint32_t *)data);
+		memcpy(&byteorder->sreg, data, sizeof(byteorder->sreg));
 		break;
 	case NFTNL_EXPR_BYTEORDER_DREG:
-		byteorder->dreg = *((uint32_t *)data);
+		memcpy(&byteorder->dreg, data, sizeof(byteorder->dreg));
 		break;
 	case NFTNL_EXPR_BYTEORDER_OP:
-		byteorder->op = *((uint32_t *)data);
+		memcpy(&byteorder->op, data, sizeof(byteorder->op));
 		break;
 	case NFTNL_EXPR_BYTEORDER_LEN:
-		byteorder->len = *((unsigned int *)data);
+		memcpy(&byteorder->len, data, sizeof(byteorder->len));
 		break;
 	case NFTNL_EXPR_BYTEORDER_SIZE:
-		byteorder->size = *((unsigned int *)data);
+		memcpy(&byteorder->size, data, sizeof(byteorder->size));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index 86708a4..e39a943 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -36,10 +36,10 @@ nftnl_expr_cmp_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_CMP_SREG:
-		cmp->sreg = *((uint32_t *)data);
+		memcpy(&cmp->sreg, data, sizeof(cmp->sreg));
 		break;
 	case NFTNL_EXPR_CMP_OP:
-		cmp->op = *((uint32_t *)data);
+		memcpy(&cmp->op, data, sizeof(cmp->op));
 		break;
 	case NFTNL_EXPR_CMP_DATA:
 		memcpy(&cmp->data.val, data, data_len);
diff --git a/src/expr/connlimit.c b/src/expr/connlimit.c
index 61fd299..9fa0a7b 100644
--- a/src/expr/connlimit.c
+++ b/src/expr/connlimit.c
@@ -33,10 +33,10 @@ nftnl_expr_connlimit_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_CONNLIMIT_COUNT:
-		connlimit->count = *((uint32_t *)data);
+		memcpy(&connlimit->count, data, sizeof(connlimit->count));
 		break;
 	case NFTNL_EXPR_CONNLIMIT_FLAGS:
-		connlimit->flags = *((uint32_t *)data);
+		memcpy(&connlimit->flags, data, sizeof(connlimit->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/counter.c b/src/expr/counter.c
index 2036cb0..a1f6574 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.c
@@ -35,10 +35,10 @@ nftnl_expr_counter_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_CTR_BYTES:
-		ctr->bytes = *((uint64_t *)data);
+		memcpy(&ctr->bytes, data, sizeof(ctr->bytes));
 		break;
 	case NFTNL_EXPR_CTR_PACKETS:
-		ctr->pkts = *((uint64_t *)data);
+		memcpy(&ctr->pkts, data, sizeof(ctr->pkts));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/ct.c b/src/expr/ct.c
index bb7fe8a..e8a8c6c 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -39,16 +39,16 @@ nftnl_expr_ct_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_CT_KEY:
-		ct->key = *((uint32_t *)data);
+		memcpy(&ct->key, data, sizeof(ct->key));
 		break;
 	case NFTNL_EXPR_CT_DIR:
-		ct->dir = *((uint8_t *)data);
+		memcpy(&ct->dir, data, sizeof(ct->dir));
 		break;
 	case NFTNL_EXPR_CT_DREG:
-		ct->dreg = *((uint32_t *)data);
+		memcpy(&ct->dreg, data, sizeof(ct->dreg));
 		break;
 	case NFTNL_EXPR_CT_SREG:
-		ct->sreg = *((uint32_t *)data);
+		memcpy(&ct->sreg, data, sizeof(ct->sreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/dup.c b/src/expr/dup.c
index 6fa6598..c08ccd2 100644
--- a/src/expr/dup.c
+++ b/src/expr/dup.c
@@ -33,10 +33,10 @@ static int nftnl_expr_dup_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_DUP_SREG_ADDR:
-		dup->sreg_addr = *((uint32_t *)data);
+		memcpy(&dup->sreg_addr, data, sizeof(dup->sreg_addr));
 		break;
 	case NFTNL_EXPR_DUP_SREG_DEV:
-		dup->sreg_dev= *((uint32_t *)data);
+		memcpy(&dup->sreg_dev, data, sizeof(dup->sreg_dev));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/dynset.c b/src/expr/dynset.c
index 3d24ef8..f009ec4 100644
--- a/src/expr/dynset.c
+++ b/src/expr/dynset.c
@@ -40,16 +40,16 @@ nftnl_expr_dynset_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_DYNSET_SREG_KEY:
-		dynset->sreg_key = *((uint32_t *)data);
+		memcpy(&dynset->sreg_key, data, sizeof(dynset->sreg_key));
 		break;
 	case NFTNL_EXPR_DYNSET_SREG_DATA:
-		dynset->sreg_data = *((uint32_t *)data);
+		memcpy(&dynset->sreg_data, data, sizeof(dynset->sreg_data));
 		break;
 	case NFTNL_EXPR_DYNSET_OP:
-		dynset->op = *((uint32_t *)data);
+		memcpy(&dynset->op, data, sizeof(dynset->op));
 		break;
 	case NFTNL_EXPR_DYNSET_TIMEOUT:
-		dynset->timeout = *((uint64_t *)data);
+		memcpy(&dynset->timeout, data, sizeof(dynset->timeout));
 		break;
 	case NFTNL_EXPR_DYNSET_SET_NAME:
 		dynset->set_name = strdup((const char *)data);
@@ -57,7 +57,7 @@ nftnl_expr_dynset_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_DYNSET_SET_ID:
-		dynset->set_id = *((uint32_t *)data);
+		memcpy(&dynset->set_id, data, sizeof(dynset->set_id));
 		break;
 	case NFTNL_EXPR_DYNSET_EXPR:
 		dynset->expr = (void *)data;
diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index ec6a855..0e09814 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -46,25 +46,25 @@ nftnl_expr_exthdr_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_EXTHDR_DREG:
-		exthdr->dreg = *((uint32_t *)data);
+		memcpy(&exthdr->dreg, data, sizeof(exthdr->dreg));
 		break;
 	case NFTNL_EXPR_EXTHDR_TYPE:
-		exthdr->type = *((uint8_t *)data);
+		memcpy(&exthdr->type, data, sizeof(exthdr->type));
 		break;
 	case NFTNL_EXPR_EXTHDR_OFFSET:
-		exthdr->offset = *((uint32_t *)data);
+		memcpy(&exthdr->offset, data, sizeof(exthdr->offset));
 		break;
 	case NFTNL_EXPR_EXTHDR_LEN:
-		exthdr->len = *((uint32_t *)data);
+		memcpy(&exthdr->len, data, sizeof(exthdr->len));
 		break;
 	case NFTNL_EXPR_EXTHDR_OP:
-		exthdr->op = *((uint32_t *)data);
+		memcpy(&exthdr->op, data, sizeof(exthdr->op));
 		break;
 	case NFTNL_EXPR_EXTHDR_FLAGS:
-		exthdr->flags = *((uint32_t *)data);
+		memcpy(&exthdr->flags, data, sizeof(exthdr->flags));
 		break;
 	case NFTNL_EXPR_EXTHDR_SREG:
-		exthdr->sreg = *((uint32_t *)data);
+		memcpy(&exthdr->sreg, data, sizeof(exthdr->sreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/fib.c b/src/expr/fib.c
index f1eec73..2f2d219 100644
--- a/src/expr/fib.c
+++ b/src/expr/fib.c
@@ -35,13 +35,13 @@ nftnl_expr_fib_set(struct nftnl_expr *e, uint16_t result,
 
 	switch (result) {
 	case NFTNL_EXPR_FIB_RESULT:
-		fib->result = *((uint32_t *)data);
+		memcpy(&fib->result, data, sizeof(fib->result));
 		break;
 	case NFTNL_EXPR_FIB_DREG:
-		fib->dreg = *((uint32_t *)data);
+		memcpy(&fib->dreg, data, sizeof(fib->dreg));
 		break;
 	case NFTNL_EXPR_FIB_FLAGS:
-		fib->flags = *((uint32_t *)data);
+		memcpy(&fib->flags, data, sizeof(fib->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/fwd.c b/src/expr/fwd.c
index 9890e9a..9cb0aca 100644
--- a/src/expr/fwd.c
+++ b/src/expr/fwd.c
@@ -34,13 +34,13 @@ static int nftnl_expr_fwd_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_FWD_SREG_DEV:
-		fwd->sreg_dev = *((uint32_t *)data);
+		memcpy(&fwd->sreg_dev, data, sizeof(fwd->sreg_dev));
 		break;
 	case NFTNL_EXPR_FWD_SREG_ADDR:
-		fwd->sreg_addr = *((uint32_t *)data);
+		memcpy(&fwd->sreg_addr, data, sizeof(fwd->sreg_addr));
 		break;
 	case NFTNL_EXPR_FWD_NFPROTO:
-		fwd->nfproto = *((uint32_t *)data);
+		memcpy(&fwd->nfproto, data, sizeof(fwd->nfproto));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/hash.c b/src/expr/hash.c
index 280ea0c..46b7901 100644
--- a/src/expr/hash.c
+++ b/src/expr/hash.c
@@ -41,25 +41,25 @@ nftnl_expr_hash_set(struct nftnl_expr *e, uint16_t type,
 	struct nftnl_expr_hash *hash = nftnl_expr_data(e);
 	switch (type) {
 	case NFTNL_EXPR_HASH_SREG:
-		hash->sreg = *((uint32_t *)data);
+		memcpy(&hash->sreg, data, sizeof(hash->sreg));
 		break;
 	case NFTNL_EXPR_HASH_DREG:
-		hash->dreg = *((uint32_t *)data);
+		memcpy(&hash->dreg, data, sizeof(hash->dreg));
 		break;
 	case NFTNL_EXPR_HASH_LEN:
-		hash->len = *((uint32_t *)data);
+		memcpy(&hash->len, data, sizeof(hash->len));
 		break;
 	case NFTNL_EXPR_HASH_MODULUS:
-		hash->modulus = *((uint32_t *)data);
+		memcpy(&hash->modulus, data, sizeof(hash->modulus));
 		break;
 	case NFTNL_EXPR_HASH_SEED:
-		hash->seed = *((uint32_t *)data);
+		memcpy(&hash->seed, data, sizeof(hash->seed));
 		break;
 	case NFTNL_EXPR_HASH_OFFSET:
-		hash->offset = *((uint32_t *)data);
+		memcpy(&hash->offset, data, sizeof(hash->offset));
 		break;
 	case NFTNL_EXPR_HASH_TYPE:
-		hash->type = *((uint32_t *)data);
+		memcpy(&hash->type, data, sizeof(hash->type));
 		break;
 	case NFTNL_EXPR_HASH_SET_NAME:
 		hash->map.name = strdup(data);
@@ -67,7 +67,7 @@ nftnl_expr_hash_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_HASH_SET_ID:
-		hash->map.id = *((uint32_t *)data);
+		memcpy(&hash->map.id, data, sizeof(hash->map.id));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index 22edbc8..d5a7e86 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -33,14 +33,14 @@ nftnl_expr_immediate_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_IMM_DREG:
-		imm->dreg = *((uint32_t *)data);
+		memcpy(&imm->dreg, data, sizeof(imm->dreg));
 		break;
 	case NFTNL_EXPR_IMM_DATA:
 		memcpy(&imm->data.val, data, data_len);
 		imm->data.len = data_len;
 		break;
 	case NFTNL_EXPR_IMM_VERDICT:
-		imm->data.verdict = *((uint32_t *)data);
+		memcpy(&imm->data.verdict, data, sizeof(imm->data.verdict));
 		break;
 	case NFTNL_EXPR_IMM_CHAIN:
 		if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN))
diff --git a/src/expr/limit.c b/src/expr/limit.c
index 4831abd..2a0adba 100644
--- a/src/expr/limit.c
+++ b/src/expr/limit.c
@@ -38,19 +38,19 @@ nftnl_expr_limit_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_LIMIT_RATE:
-		limit->rate = *((uint64_t *)data);
+		memcpy(&limit->rate, data, sizeof(limit->rate));
 		break;
 	case NFTNL_EXPR_LIMIT_UNIT:
-		limit->unit = *((uint64_t *)data);
+		memcpy(&limit->unit, data, sizeof(limit->unit));
 		break;
 	case NFTNL_EXPR_LIMIT_BURST:
-		limit->burst = *((uint32_t *)data);
+		memcpy(&limit->burst, data, sizeof(limit->burst));
 		break;
 	case NFTNL_EXPR_LIMIT_TYPE:
-		limit->type = *((uint32_t *)data);
+		memcpy(&limit->type, data, sizeof(limit->type));
 		break;
 	case NFTNL_EXPR_LIMIT_FLAGS:
-		limit->flags = *((uint32_t *)data);
+		memcpy(&limit->flags, data, sizeof(limit->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/log.c b/src/expr/log.c
index e4bf051..1119c53 100644
--- a/src/expr/log.c
+++ b/src/expr/log.c
@@ -46,19 +46,19 @@ static int nftnl_expr_log_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_LOG_GROUP:
-		log->group = *((uint16_t *)data);
+		memcpy(&log->group, data, sizeof(log->group));
 		break;
 	case NFTNL_EXPR_LOG_SNAPLEN:
-		log->snaplen = *((uint32_t *)data);
+		memcpy(&log->snaplen, data, sizeof(log->snaplen));
 		break;
 	case NFTNL_EXPR_LOG_QTHRESHOLD:
-		log->qthreshold = *((uint16_t *)data);
+		memcpy(&log->qthreshold, data, sizeof(log->qthreshold));
 		break;
 	case NFTNL_EXPR_LOG_LEVEL:
-		log->level = *((uint32_t *)data);
+		memcpy(&log->level, data, sizeof(log->level));
 		break;
 	case NFTNL_EXPR_LOG_FLAGS:
-		log->flags = *((uint32_t *)data);
+		memcpy(&log->flags, data, sizeof(log->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 132dc4e..a502e2a 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -37,10 +37,10 @@ nftnl_expr_lookup_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_LOOKUP_SREG:
-		lookup->sreg = *((uint32_t *)data);
+		memcpy(&lookup->sreg, data, sizeof(lookup->sreg));
 		break;
 	case NFTNL_EXPR_LOOKUP_DREG:
-		lookup->dreg = *((uint32_t *)data);
+		memcpy(&lookup->dreg, data, sizeof(lookup->dreg));
 		break;
 	case NFTNL_EXPR_LOOKUP_SET:
 		lookup->set_name = strdup((const char *)data);
@@ -48,10 +48,10 @@ nftnl_expr_lookup_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_LOOKUP_SET_ID:
-		lookup->set_id = *((uint32_t *)data);
+		memcpy(&lookup->set_id, data, sizeof(lookup->set_id));
 		break;
 	case NFTNL_EXPR_LOOKUP_FLAGS:
-		lookup->flags = *((uint32_t *)data);
+		memcpy(&lookup->flags, data, sizeof(lookup->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/masq.c b/src/expr/masq.c
index 78dd76b..fe017f7 100644
--- a/src/expr/masq.c
+++ b/src/expr/masq.c
@@ -34,13 +34,13 @@ nftnl_expr_masq_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_MASQ_FLAGS:
-		masq->flags = *((uint32_t *)data);
+		memcpy(&masq->flags, data, sizeof(masq->flags));
 		break;
 	case NFTNL_EXPR_MASQ_REG_PROTO_MIN:
-		masq->sreg_proto_min = *((uint32_t *)data);
+		memcpy(&masq->sreg_proto_min, data, sizeof(masq->sreg_proto_min));
 		break;
 	case NFTNL_EXPR_MASQ_REG_PROTO_MAX:
-		masq->sreg_proto_max = *((uint32_t *)data);
+		memcpy(&masq->sreg_proto_max, data, sizeof(masq->sreg_proto_max));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/match.c b/src/expr/match.c
index 85dd79c..2b3321d 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -46,7 +46,7 @@ nftnl_expr_match_set(struct nftnl_expr *e, uint16_t type,
 			 (const char *)data);
 		break;
 	case NFTNL_EXPR_MT_REV:
-		mt->rev = *((uint32_t *)data);
+		memcpy(&mt->rev, data, sizeof(mt->rev));
 		break;
 	case NFTNL_EXPR_MT_INFO:
 		if (e->flags & (1 << NFTNL_EXPR_MT_INFO))
diff --git a/src/expr/meta.c b/src/expr/meta.c
index b66b9b7..3654837 100644
--- a/src/expr/meta.c
+++ b/src/expr/meta.c
@@ -39,13 +39,13 @@ nftnl_expr_meta_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_META_KEY:
-		meta->key = *((uint32_t *)data);
+		memcpy(&meta->key, data, sizeof(meta->key));
 		break;
 	case NFTNL_EXPR_META_DREG:
-		meta->dreg = *((uint32_t *)data);
+		memcpy(&meta->dreg, data, sizeof(meta->dreg));
 		break;
 	case NFTNL_EXPR_META_SREG:
-		meta->sreg = *((uint32_t *)data);
+		memcpy(&meta->sreg, data, sizeof(meta->sreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/nat.c b/src/expr/nat.c
index 9be78f3..38fccb0 100644
--- a/src/expr/nat.c
+++ b/src/expr/nat.c
@@ -42,25 +42,25 @@ nftnl_expr_nat_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_NAT_TYPE:
-		nat->type = *((uint32_t *)data);
+		memcpy(&nat->type, data, sizeof(nat->type));
 		break;
 	case NFTNL_EXPR_NAT_FAMILY:
-		nat->family = *((uint32_t *)data);
+		memcpy(&nat->family, data, sizeof(nat->family));
 		break;
 	case NFTNL_EXPR_NAT_REG_ADDR_MIN:
-		nat->sreg_addr_min = *((uint32_t *)data);
+		memcpy(&nat->sreg_addr_min, data, sizeof(nat->sreg_addr_min));
 		break;
 	case NFTNL_EXPR_NAT_REG_ADDR_MAX:
-		nat->sreg_addr_max = *((uint32_t *)data);
+		memcpy(&nat->sreg_addr_max, data, sizeof(nat->sreg_addr_max));
 		break;
 	case NFTNL_EXPR_NAT_REG_PROTO_MIN:
-		nat->sreg_proto_min = *((uint32_t *)data);
+		memcpy(&nat->sreg_proto_min, data, sizeof(nat->sreg_proto_min));
 		break;
 	case NFTNL_EXPR_NAT_REG_PROTO_MAX:
-		nat->sreg_proto_max = *((uint32_t *)data);
+		memcpy(&nat->sreg_proto_max, data, sizeof(nat->sreg_proto_max));
 		break;
 	case NFTNL_EXPR_NAT_FLAGS:
-		nat->flags = *((uint32_t *)data);
+		memcpy(&nat->flags, data, sizeof(nat->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/numgen.c b/src/expr/numgen.c
index d46cf94..f940081 100644
--- a/src/expr/numgen.c
+++ b/src/expr/numgen.c
@@ -39,16 +39,16 @@ nftnl_expr_ng_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_NG_DREG:
-		ng->dreg = *((uint32_t *)data);
+		memcpy(&ng->dreg, data, sizeof(ng->dreg));
 		break;
 	case NFTNL_EXPR_NG_MODULUS:
-		ng->modulus = *((uint32_t *)data);
+		memcpy(&ng->modulus, data, sizeof(ng->modulus));
 		break;
 	case NFTNL_EXPR_NG_TYPE:
-		ng->type = *((uint32_t *)data);
+		memcpy(&ng->type, data, sizeof(ng->type));
 		break;
 	case NFTNL_EXPR_NG_OFFSET:
-		ng->offset = *((uint32_t *)data);
+		memcpy(&ng->offset, data, sizeof(ng->offset));
 		break;
 	case NFTNL_EXPR_NG_SET_NAME:
 		ng->map.name = strdup(data);
@@ -56,7 +56,7 @@ nftnl_expr_ng_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_NG_SET_ID:
-		ng->map.id = *((uint32_t *)data);
+		memcpy(&ng->map.id, data, sizeof(ng->map.id));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/objref.c b/src/expr/objref.c
index 67fd74b..3b815f5 100644
--- a/src/expr/objref.c
+++ b/src/expr/objref.c
@@ -39,7 +39,7 @@ static int nftnl_expr_objref_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_OBJREF_IMM_TYPE:
-		objref->imm.type = *((uint32_t *)data);
+		memcpy(&objref->imm.type, data, sizeof(objref->imm.type));
 		break;
 	case NFTNL_EXPR_OBJREF_IMM_NAME:
 		objref->imm.name = strdup(data);
@@ -47,7 +47,7 @@ static int nftnl_expr_objref_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_OBJREF_SET_SREG:
-		objref->set.sreg = *((uint32_t *)data);
+		memcpy(&objref->set.sreg, data, sizeof(objref->set.sreg));
 		break;
 	case NFTNL_EXPR_OBJREF_SET_NAME:
 		objref->set.name = strdup(data);
@@ -55,7 +55,7 @@ static int nftnl_expr_objref_set(struct nftnl_expr *e, uint16_t type,
 			return -1;
 		break;
 	case NFTNL_EXPR_OBJREF_SET_ID:
-		objref->set.id = *((uint32_t *)data);
+		memcpy(&objref->set.id, data, sizeof(objref->set.id));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/osf.c b/src/expr/osf.c
index a90620d..0860328 100644
--- a/src/expr/osf.c
+++ b/src/expr/osf.c
@@ -24,10 +24,10 @@ static int nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_OSF_DREG:
-		osf->dreg = *((uint32_t *)data);
+		memcpy(&osf->dreg, data, sizeof(osf->dreg));
 		break;
 	case NFTNL_EXPR_OSF_TTL:
-		osf->ttl = *((uint8_t *)data);
+		memcpy(&osf->ttl, data, sizeof(osf->ttl));
 		break;
 	}
 	return 0;
diff --git a/src/expr/payload.c b/src/expr/payload.c
index 4b2f322..680da4a 100644
--- a/src/expr/payload.c
+++ b/src/expr/payload.c
@@ -43,28 +43,28 @@ nftnl_expr_payload_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_PAYLOAD_SREG:
-		payload->sreg = *((uint32_t *)data);
+		memcpy(&payload->sreg, data, sizeof(payload->sreg));
 		break;
 	case NFTNL_EXPR_PAYLOAD_DREG:
-		payload->dreg = *((uint32_t *)data);
+		memcpy(&payload->dreg, data, sizeof(payload->dreg));
 		break;
 	case NFTNL_EXPR_PAYLOAD_BASE:
-		payload->base = *((uint32_t *)data);
+		memcpy(&payload->base, data, sizeof(payload->base));
 		break;
 	case NFTNL_EXPR_PAYLOAD_OFFSET:
-		payload->offset = *((unsigned int *)data);
+		memcpy(&payload->offset, data, sizeof(payload->offset));
 		break;
 	case NFTNL_EXPR_PAYLOAD_LEN:
-		payload->len = *((unsigned int *)data);
+		memcpy(&payload->len, data, sizeof(payload->len));
 		break;
 	case NFTNL_EXPR_PAYLOAD_CSUM_TYPE:
-		payload->csum_type = *((uint32_t *)data);
+		memcpy(&payload->csum_type, data, sizeof(payload->csum_type));
 		break;
 	case NFTNL_EXPR_PAYLOAD_CSUM_OFFSET:
-		payload->csum_offset = *((uint32_t *)data);
+		memcpy(&payload->csum_offset, data, sizeof(payload->csum_offset));
 		break;
 	case NFTNL_EXPR_PAYLOAD_FLAGS:
-		payload->csum_flags = *((uint32_t *)data);
+		memcpy(&payload->csum_flags, data, sizeof(payload->csum_flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/queue.c b/src/expr/queue.c
index e71df7d..f9d8313 100644
--- a/src/expr/queue.c
+++ b/src/expr/queue.c
@@ -34,16 +34,16 @@ static int nftnl_expr_queue_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_QUEUE_NUM:
-		queue->queuenum = *((uint16_t *)data);
+		memcpy(&queue->queuenum, data, sizeof(queue->queuenum));
 		break;
 	case NFTNL_EXPR_QUEUE_TOTAL:
-		queue->queues_total = *((uint16_t *)data);
+		memcpy(&queue->queues_total, data, sizeof(queue->queues_total));
 		break;
 	case NFTNL_EXPR_QUEUE_FLAGS:
-		queue->flags = *((uint16_t *)data);
+		memcpy(&queue->flags, data, sizeof(queue->flags));
 		break;
 	case NFTNL_EXPR_QUEUE_SREG_QNUM:
-		queue->sreg_qnum = *((uint32_t *)data);
+		memcpy(&queue->sreg_qnum, data, sizeof(queue->sreg_qnum));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/quota.c b/src/expr/quota.c
index b280852..39a92e6 100644
--- a/src/expr/quota.c
+++ b/src/expr/quota.c
@@ -33,13 +33,13 @@ static int nftnl_expr_quota_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_QUOTA_BYTES:
-		quota->bytes = *((uint64_t *)data);
+		memcpy(&quota->bytes, data, sizeof(quota->bytes));
 		break;
 	case NFTNL_EXPR_QUOTA_CONSUMED:
-		quota->consumed = *((uint64_t *)data);
+		memcpy(&quota->consumed, data, sizeof(quota->consumed));
 		break;
 	case NFTNL_EXPR_QUOTA_FLAGS:
-		quota->flags = *((uint32_t *)data);
+		memcpy(&quota->flags, data, sizeof(quota->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/range.c b/src/expr/range.c
index f5a41ac..d1d5083 100644
--- a/src/expr/range.c
+++ b/src/expr/range.c
@@ -34,10 +34,10 @@ static int nftnl_expr_range_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_RANGE_SREG:
-		range->sreg = *((uint32_t *)data);
+		memcpy(&range->sreg, data, sizeof(range->sreg));
 		break;
 	case NFTNL_EXPR_RANGE_OP:
-		range->op = *((uint32_t *)data);
+		memcpy(&range->op, data, sizeof(range->op));
 		break;
 	case NFTNL_EXPR_RANGE_FROM_DATA:
 		memcpy(&range->data_from.val, data, data_len);
diff --git a/src/expr/redir.c b/src/expr/redir.c
index 1ed4896..36c2e2b 100644
--- a/src/expr/redir.c
+++ b/src/expr/redir.c
@@ -34,13 +34,13 @@ nftnl_expr_redir_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_REDIR_REG_PROTO_MIN:
-		redir->sreg_proto_min = *((uint32_t *)data);
+		memcpy(&redir->sreg_proto_min, data, sizeof(redir->sreg_proto_min));
 		break;
 	case NFTNL_EXPR_REDIR_REG_PROTO_MAX:
-		redir->sreg_proto_max = *((uint32_t *)data);
+		memcpy(&redir->sreg_proto_max, data, sizeof(redir->sreg_proto_max));
 		break;
 	case NFTNL_EXPR_REDIR_FLAGS:
-		redir->flags = *((uint32_t *)data);
+		memcpy(&redir->flags, data, sizeof(redir->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/reject.c b/src/expr/reject.c
index b26b0cc..3e49076 100644
--- a/src/expr/reject.c
+++ b/src/expr/reject.c
@@ -33,10 +33,10 @@ static int nftnl_expr_reject_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_REJECT_TYPE:
-		reject->type = *((uint32_t *)data);
+		memcpy(&reject->type, data, sizeof(reject->type));
 		break;
 	case NFTNL_EXPR_REJECT_CODE:
-		reject->icmp_code = *((uint8_t *)data);
+		memcpy(&reject->icmp_code, data, sizeof(reject->icmp_code));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/rt.c b/src/expr/rt.c
index 2c0c1cf..a112270 100644
--- a/src/expr/rt.c
+++ b/src/expr/rt.c
@@ -32,10 +32,10 @@ nftnl_expr_rt_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_RT_KEY:
-		rt->key = *((uint32_t *)data);
+		memcpy(&rt->key, data, sizeof(rt->key));
 		break;
 	case NFTNL_EXPR_RT_DREG:
-		rt->dreg = *((uint32_t *)data);
+		memcpy(&rt->dreg, data, sizeof(rt->dreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/socket.c b/src/expr/socket.c
index 704b1d9..ebafa2f 100644
--- a/src/expr/socket.c
+++ b/src/expr/socket.c
@@ -32,10 +32,10 @@ nftnl_expr_socket_set(struct nftnl_expr *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_EXPR_SOCKET_KEY:
-		socket->key = *((uint32_t *)data);
+		memcpy(&socket->key, data, sizeof(socket->key));
 		break;
 	case NFTNL_EXPR_SOCKET_DREG:
-		socket->dreg = *((uint32_t *)data);
+		memcpy(&socket->dreg, data, sizeof(socket->dreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/target.c b/src/expr/target.c
index 6ae6c81..bf2ba77 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -46,7 +46,7 @@ nftnl_expr_target_set(struct nftnl_expr *e, uint16_t type,
 			 (const char *) data);
 		break;
 	case NFTNL_EXPR_TG_REV:
-		tg->rev = *((uint32_t *)data);
+		memcpy(&tg->rev, data, sizeof(tg->rev));
 		break;
 	case NFTNL_EXPR_TG_INFO:
 		if (e->flags & (1 << NFTNL_EXPR_TG_INFO))
diff --git a/src/expr/tproxy.c b/src/expr/tproxy.c
index 6fae172..d75abbc 100644
--- a/src/expr/tproxy.c
+++ b/src/expr/tproxy.c
@@ -34,13 +34,13 @@ nftnl_expr_tproxy_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_TPROXY_FAMILY:
-		tproxy->family = *((uint32_t *)data);
+		memcpy(&tproxy->family, data, sizeof(tproxy->family));
 		break;
 	case NFTNL_EXPR_TPROXY_REG_ADDR:
-		tproxy->sreg_addr = *((uint32_t *)data);
+		memcpy(&tproxy->sreg_addr, data, sizeof(tproxy->sreg_addr));
 		break;
 	case NFTNL_EXPR_TPROXY_REG_PORT:
-		tproxy->sreg_port = *((uint32_t *)data);
+		memcpy(&tproxy->sreg_port, data, sizeof(tproxy->sreg_port));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/tunnel.c b/src/expr/tunnel.c
index 677e968..b2b8d72 100644
--- a/src/expr/tunnel.c
+++ b/src/expr/tunnel.c
@@ -31,10 +31,10 @@ static int nftnl_expr_tunnel_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_TUNNEL_KEY:
-		tunnel->key = *((uint32_t *)data);
+		memcpy(&tunnel->key, data, sizeof(tunnel->key));
 		break;
 	case NFTNL_EXPR_TUNNEL_DREG:
-		tunnel->dreg = *((uint32_t *)data);
+		memcpy(&tunnel->dreg, data, sizeof(tunnel->dreg));
 		break;
 	default:
 		return -1;
diff --git a/src/expr/xfrm.c b/src/expr/xfrm.c
index dd3062c..7c6f98e 100644
--- a/src/expr/xfrm.c
+++ b/src/expr/xfrm.c
@@ -33,16 +33,16 @@ nftnl_expr_xfrm_set(struct nftnl_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_EXPR_XFRM_KEY:
-		x->key = *((uint32_t *)data);
+		memcpy(&x->key, data, sizeof(x->key));
 		break;
 	case NFTNL_EXPR_XFRM_DIR:
-		x->dir = *((uint8_t *)data);
+		memcpy(&x->dir, data, sizeof(x->dir));
 		break;
 	case NFTNL_EXPR_XFRM_SPNUM:
-		x->spnum = *((uint32_t *)data);
+		memcpy(&x->spnum, data, sizeof(x->spnum));
 		break;
 	case NFTNL_EXPR_XFRM_DREG:
-		x->dreg = *((uint32_t *)data);
+		memcpy(&x->dreg, data, sizeof(x->dreg));
 		break;
 	default:
 		return -1;
diff --git a/src/gen.c b/src/gen.c
index 8e1a37a..1fc9099 100644
--- a/src/gen.c
+++ b/src/gen.c
@@ -73,7 +73,7 @@ int nftnl_gen_set_data(struct nftnl_gen *gen, uint16_t attr,
 
 	switch (attr) {
 	case NFTNL_GEN_ID:
-		gen->id = *((uint32_t *)data);
+		memcpy(&gen->id, data, sizeof(gen->id));
 		break;
 	}
 	gen->flags |= (1 << attr);
diff --git a/src/obj/counter.c b/src/obj/counter.c
index 23b60c5..1baba4e 100644
--- a/src/obj/counter.c
+++ b/src/obj/counter.c
@@ -29,10 +29,10 @@ nftnl_obj_counter_set(struct nftnl_obj *e, uint16_t type,
 
 	switch(type) {
 	case NFTNL_OBJ_CTR_BYTES:
-		ctr->bytes = *((uint64_t *)data);
+		memcpy(&ctr->bytes, data, sizeof(ctr->bytes));
 		break;
 	case NFTNL_OBJ_CTR_PKTS:
-		ctr->pkts = *((uint64_t *)data);
+		memcpy(&ctr->pkts, data, sizeof(ctr->pkts));
 		break;
 	default:
 		return -1;
diff --git a/src/obj/ct_helper.c b/src/obj/ct_helper.c
index 5a689b1..d91f636 100644
--- a/src/obj/ct_helper.c
+++ b/src/obj/ct_helper.c
@@ -32,10 +32,10 @@ static int nftnl_obj_ct_helper_set(struct nftnl_obj *e, uint16_t type,
 		snprintf(helper->name, sizeof(helper->name), "%s", (const char *)data);
 		break;
 	case NFTNL_OBJ_CT_HELPER_L3PROTO:
-		helper->l3proto = *((uint16_t *)data);
+		memcpy(&helper->l3proto, data, sizeof(helper->l3proto));
 		break;
 	case NFTNL_OBJ_CT_HELPER_L4PROTO:
-		helper->l4proto = *((uint8_t *)data);
+		memcpy(&helper->l4proto, data, sizeof(helper->l4proto));
 		break;
 	default:
 		return -1;
diff --git a/src/obj/ct_timeout.c b/src/obj/ct_timeout.c
index 12c8f5f..e2e9991 100644
--- a/src/obj/ct_timeout.c
+++ b/src/obj/ct_timeout.c
@@ -148,10 +148,10 @@ static int nftnl_obj_ct_timeout_set(struct nftnl_obj *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_OBJ_CT_TIMEOUT_L3PROTO:
-		timeout->l3proto = *((uint16_t *)data);
+		memcpy(&timeout->l3proto, data, sizeof(timeout->l3proto));
 		break;
 	case NFTNL_OBJ_CT_TIMEOUT_L4PROTO:
-		timeout->l4proto = *((uint8_t *)data);
+		memcpy(&timeout->l4proto, data, sizeof(timeout->l4proto));
 		break;
 	case NFTNL_OBJ_CT_TIMEOUT_ARRAY:
 		memcpy(timeout->timeout, data,
diff --git a/src/obj/limit.c b/src/obj/limit.c
index b0ed4c8..60b0159 100644
--- a/src/obj/limit.c
+++ b/src/obj/limit.c
@@ -28,19 +28,19 @@ static int nftnl_obj_limit_set(struct nftnl_obj *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_OBJ_LIMIT_RATE:
-		limit->rate = *((uint64_t *)data);
+		memcpy(&limit->rate, data, sizeof(limit->rate));
 		break;
 	case NFTNL_OBJ_LIMIT_UNIT:
-		limit->unit = *((uint64_t *)data);
+		memcpy(&limit->unit, data, sizeof(limit->unit));
 		break;
 	case NFTNL_OBJ_LIMIT_BURST:
-		limit->burst = *((uint32_t *)data);
+		memcpy(&limit->burst, data, sizeof(limit->burst));
 		break;
 	case NFTNL_OBJ_LIMIT_TYPE:
-		limit->type = *((uint32_t *)data);
+		memcpy(&limit->type, data, sizeof(limit->type));
 		break;
 	case NFTNL_OBJ_LIMIT_FLAGS:
-		limit->flags = *((uint32_t *)data);
+		memcpy(&limit->flags, data, sizeof(limit->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/obj/quota.c b/src/obj/quota.c
index b1a3f7e..1914037 100644
--- a/src/obj/quota.c
+++ b/src/obj/quota.c
@@ -28,13 +28,13 @@ static int nftnl_obj_quota_set(struct nftnl_obj *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_OBJ_QUOTA_BYTES:
-		quota->bytes = *((uint64_t *)data);
+		memcpy(&quota->bytes, data, sizeof(quota->bytes));
 		break;
 	case NFTNL_OBJ_QUOTA_CONSUMED:
-		quota->consumed = *((uint64_t *)data);
+		memcpy(&quota->consumed, data, sizeof(quota->consumed));
 		break;
 	case NFTNL_OBJ_QUOTA_FLAGS:
-		quota->flags = *((uint32_t *)data);
+		memcpy(&quota->flags, data, sizeof(quota->flags));
 		break;
 	default:
 		return -1;
diff --git a/src/obj/tunnel.c b/src/obj/tunnel.c
index 5b2d9de..7ffade8 100644
--- a/src/obj/tunnel.c
+++ b/src/obj/tunnel.c
@@ -29,13 +29,13 @@ nftnl_obj_tunnel_set(struct nftnl_obj *e, uint16_t type,
 
 	switch (type) {
 	case NFTNL_OBJ_TUNNEL_ID:
-		tun->id = *((uint32_t *)data);
+		memcpy(&tun->id, data, sizeof(tun->id));
 		break;
 	case NFTNL_OBJ_TUNNEL_IPV4_SRC:
-		tun->src_v4 = *((uint32_t *)data);
+		memcpy(&tun->src_v4, data, sizeof(tun->src_v4));
 		break;
 	case NFTNL_OBJ_TUNNEL_IPV4_DST:
-		tun->dst_v4 = *((uint32_t *)data);
+		memcpy(&tun->dst_v4, data, sizeof(tun->dst_v4));
 		break;
 	case NFTNL_OBJ_TUNNEL_IPV6_SRC:
 		memcpy(&tun->src_v6, data, sizeof(struct in6_addr));
@@ -44,37 +44,37 @@ nftnl_obj_tunnel_set(struct nftnl_obj *e, uint16_t type,
 		memcpy(&tun->dst_v6, data, sizeof(struct in6_addr));
 		break;
 	case NFTNL_OBJ_TUNNEL_IPV6_FLOWLABEL:
-		tun->flowlabel = (*(uint32_t *)data);
+		memcpy(&tun->flowlabel, data, sizeof(tun->flowlabel));
 		break;
 	case NFTNL_OBJ_TUNNEL_SPORT:
-		tun->sport = (*(uint16_t *)data);
+		memcpy(&tun->sport, data, sizeof(tun->sport));
 		break;
 	case NFTNL_OBJ_TUNNEL_DPORT:
-		tun->dport = (*(uint16_t *)data);
+		memcpy(&tun->dport, data, sizeof(tun->dport));
 		break;
 	case NFTNL_OBJ_TUNNEL_FLAGS:
-		tun->tun_flags = (*(uint32_t *)data);
+		memcpy(&tun->tun_flags, data, sizeof(tun->tun_flags));
 		break;
 	case NFTNL_OBJ_TUNNEL_TOS:
-		tun->tun_tos = (*(uint8_t *)data);
+		memcpy(&tun->tun_tos, data, sizeof(tun->tun_tos));
 		break;
 	case NFTNL_OBJ_TUNNEL_TTL:
-		tun->tun_ttl = (*(uint8_t *)data);
+		memcpy(&tun->tun_ttl, data, sizeof(tun->tun_ttl));
 		break;
 	case NFTNL_OBJ_TUNNEL_VXLAN_GBP:
-		tun->u.tun_vxlan.gbp = (*(uint32_t *)data);
+		memcpy(&tun->u.tun_vxlan.gbp, data, sizeof(tun->u.tun_vxlan.gbp));
 		break;
 	case NFTNL_OBJ_TUNNEL_ERSPAN_VERSION:
-		tun->u.tun_erspan.version = (*(uint32_t *)data);
+		memcpy(&tun->u.tun_erspan.version, data, sizeof(tun->u.tun_erspan.version));
 		break;
 	case NFTNL_OBJ_TUNNEL_ERSPAN_V1_INDEX:
-		tun->u.tun_erspan.u.v1_index = (*(uint32_t *)data);
+		memcpy(&tun->u.tun_erspan.u.v1_index, data, sizeof(tun->u.tun_erspan.u.v1_index));
 		break;
 	case NFTNL_OBJ_TUNNEL_ERSPAN_V2_HWID:
-		tun->u.tun_erspan.u.v2.hwid = (*(uint8_t *)data);
+		memcpy(&tun->u.tun_erspan.u.v2.hwid, data, sizeof(tun->u.tun_erspan.u.v2.hwid));
 		break;
 	case NFTNL_OBJ_TUNNEL_ERSPAN_V2_DIR:
-		tun->u.tun_erspan.u.v2.dir = (*(uint8_t *)data);
+		memcpy(&tun->u.tun_erspan.u.v2.dir, data, sizeof(tun->u.tun_erspan.u.v2.dir));
 		break;
 	default:
 		return -1;
diff --git a/src/object.c b/src/object.c
index a1a553f..e88203a 100644
--- a/src/object.c
+++ b/src/object.c
@@ -94,13 +94,13 @@ void nftnl_obj_set_data(struct nftnl_obj *obj, uint16_t attr,
 			return;
 		break;
 	case NFTNL_OBJ_FAMILY:
-		obj->family = *((uint32_t *)data);
+		memcpy(&obj->family, data, sizeof(obj->family));
 		break;
 	case NFTNL_OBJ_USE:
-		obj->use = *((uint32_t *)data);
+		memcpy(&obj->use, data, sizeof(obj->use));
 		break;
 	case NFTNL_OBJ_HANDLE:
-		obj->handle = *((uint64_t *)data);
+		memcpy(&obj->handle, data, sizeof(obj->handle));
 		break;
 	default:
 		if (obj->ops)
diff --git a/src/rule.c b/src/rule.c
index a42d087..c3c8a8b 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -152,19 +152,19 @@ int nftnl_rule_set_data(struct nftnl_rule *r, uint16_t attr,
 			return -1;
 		break;
 	case NFTNL_RULE_HANDLE:
-		r->handle = *((uint64_t *)data);
+		memcpy(&r->handle, data, sizeof(r->handle));
 		break;
 	case NFTNL_RULE_COMPAT_PROTO:
-		r->compat.proto = *((uint32_t *)data);
+		memcpy(&r->compat.proto, data, sizeof(r->compat.proto));
 		break;
 	case NFTNL_RULE_COMPAT_FLAGS:
-		r->compat.flags = *((uint32_t *)data);
+		memcpy(&r->compat.flags, data, sizeof(r->compat.flags));
 		break;
 	case NFTNL_RULE_FAMILY:
-		r->family = *((uint32_t *)data);
+		memcpy(&r->family, data, sizeof(r->family));
 		break;
 	case NFTNL_RULE_POSITION:
-		r->position = *((uint64_t *)data);
+		memcpy(&r->position, data, sizeof(r->position));
 		break;
 	case NFTNL_RULE_USERDATA:
 		if (r->flags & (1 << NFTNL_RULE_USERDATA))
@@ -178,7 +178,7 @@ int nftnl_rule_set_data(struct nftnl_rule *r, uint16_t attr,
 		r->user.len = data_len;
 		break;
 	case NFTNL_RULE_ID:
-		r->id = *((uint32_t *)data);
+		memcpy(&r->id, data, sizeof(r->id));
 		break;
 	}
 	r->flags |= (1 << attr);
diff --git a/src/set.c b/src/set.c
index 7472422..d1bdb16 100644
--- a/src/set.c
+++ b/src/set.c
@@ -142,43 +142,43 @@ int nftnl_set_set_data(struct nftnl_set *s, uint16_t attr, const void *data,
 			return -1;
 		break;
 	case NFTNL_SET_HANDLE:
-		s->handle = *((uint64_t *)data);
+		memcpy(&s->handle, data, sizeof(s->handle));
 		break;
 	case NFTNL_SET_FLAGS:
-		s->set_flags = *((uint32_t *)data);
+		memcpy(&s->set_flags, data, sizeof(s->set_flags));
 		break;
 	case NFTNL_SET_KEY_TYPE:
-		s->key_type = *((uint32_t *)data);
+		memcpy(&s->key_type, data, sizeof(s->key_type));
 		break;
 	case NFTNL_SET_KEY_LEN:
-		s->key_len = *((uint32_t *)data);
+		memcpy(&s->key_len, data, sizeof(s->key_len));
 		break;
 	case NFTNL_SET_DATA_TYPE:
-		s->data_type = *((uint32_t *)data);
+		memcpy(&s->data_type, data, sizeof(s->data_type));
 		break;
 	case NFTNL_SET_DATA_LEN:
-		s->data_len = *((uint32_t *)data);
+		memcpy(&s->data_len, data, sizeof(s->data_len));
 		break;
 	case NFTNL_SET_OBJ_TYPE:
-		s->obj_type = *((uint32_t *)data);
+		memcpy(&s->obj_type, data, sizeof(s->obj_type));
 		break;
 	case NFTNL_SET_FAMILY:
-		s->family = *((uint32_t *)data);
+		memcpy(&s->family, data, sizeof(s->family));
 		break;
 	case NFTNL_SET_ID:
-		s->id = *((uint32_t *)data);
+		memcpy(&s->id, data, sizeof(s->id));
 		break;
 	case NFTNL_SET_POLICY:
-		s->policy = *((uint32_t *)data);
+		memcpy(&s->policy, data, sizeof(s->policy));
 		break;
 	case NFTNL_SET_DESC_SIZE:
-		s->desc.size = *((uint32_t *)data);
+		memcpy(&s->desc.size, data, sizeof(s->desc.size));
 		break;
 	case NFTNL_SET_TIMEOUT:
-		s->timeout = *((uint64_t *)data);
+		memcpy(&s->timeout, data, sizeof(s->timeout));
 		break;
 	case NFTNL_SET_GC_INTERVAL:
-		s->gc_interval = *((uint32_t *)data);
+		memcpy(&s->gc_interval, data, sizeof(s->gc_interval));
 		break;
 	case NFTNL_SET_USERDATA:
 		if (s->flags & (1 << NFTNL_SET_USERDATA))
diff --git a/src/set_elem.c b/src/set_elem.c
index bb8d046..4dc21b7 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -102,14 +102,14 @@ int nftnl_set_elem_set(struct nftnl_set_elem *s, uint16_t attr,
 {
 	switch(attr) {
 	case NFTNL_SET_ELEM_FLAGS:
-		s->set_elem_flags = *((uint32_t *)data);
+		memcpy(&s->set_elem_flags, data, sizeof(s->set_elem_flags));
 		break;
 	case NFTNL_SET_ELEM_KEY:	/* NFTA_SET_ELEM_KEY */
 		memcpy(&s->key.val, data, data_len);
 		s->key.len = data_len;
 		break;
 	case NFTNL_SET_ELEM_VERDICT:	/* NFTA_SET_ELEM_DATA */
-		s->data.verdict = *((uint32_t *)data);
+		memcpy(&s->data.verdict, data, sizeof(s->data.verdict));
 		break;
 	case NFTNL_SET_ELEM_CHAIN:	/* NFTA_SET_ELEM_DATA */
 		if (s->flags & (1 << NFTNL_SET_ELEM_CHAIN))
@@ -124,7 +124,7 @@ int nftnl_set_elem_set(struct nftnl_set_elem *s, uint16_t attr,
 		s->data.len = data_len;
 		break;
 	case NFTNL_SET_ELEM_TIMEOUT:	/* NFTA_SET_ELEM_TIMEOUT */
-		s->timeout = *((uint64_t *)data);
+		memcpy(&s->timeout, data, sizeof(s->timeout));
 		break;
 	case NFTNL_SET_ELEM_USERDATA: /* NFTA_SET_ELEM_USERDATA */
 		if (s->flags & (1 << NFTNL_SET_ELEM_USERDATA))
@@ -219,7 +219,8 @@ EXPORT_SYMBOL(nftnl_set_elem_get_u32);
 uint32_t nftnl_set_elem_get_u32(struct nftnl_set_elem *s, uint16_t attr)
 {
 	uint32_t size;
-	uint32_t val = *((uint32_t *)nftnl_set_elem_get(s, attr, &size));
+	uint32_t val;
+	memcpy(&val, nftnl_set_elem_get(s, attr, &size), sizeof(val));
 	return val;
 }
 
@@ -227,7 +228,8 @@ EXPORT_SYMBOL(nftnl_set_elem_get_u64);
 uint64_t nftnl_set_elem_get_u64(struct nftnl_set_elem *s, uint16_t attr)
 {
 	uint32_t size;
-	uint64_t val = *((uint64_t *)nftnl_set_elem_get(s, attr, &size));
+	uint64_t val;
+	memcpy(&val, nftnl_set_elem_get(s, attr, &size), sizeof(val));
 	return val;
 }
 
diff --git a/src/table.c b/src/table.c
index c987c5e..54259ee 100644
--- a/src/table.c
+++ b/src/table.c
@@ -101,16 +101,16 @@ int nftnl_table_set_data(struct nftnl_table *t, uint16_t attr,
 			return -1;
 		break;
 	case NFTNL_TABLE_HANDLE:
-		t->handle = *((uint64_t *)data);
+		memcpy(&t->handle, data, sizeof(t->handle));
 		break;
 	case NFTNL_TABLE_FLAGS:
-		t->table_flags = *((uint32_t *)data);
+		memcpy(&t->table_flags, data, sizeof(t->table_flags));
 		break;
 	case NFTNL_TABLE_FAMILY:
-		t->family = *((uint32_t *)data);
+		memcpy(&t->family, data, sizeof(t->family));
 		break;
 	case NFTNL_TABLE_USE:
-		t->use = *((uint32_t *)data);
+		memcpy(&t->use, data, sizeof(t->use));
 		break;
 	}
 	t->flags |= (1 << attr);
diff --git a/src/utils.c b/src/utils.c
index 4d9ee78..f641bf9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -89,7 +89,7 @@ int nftnl_get_value(enum nftnl_type type, void *val, void *out)
 	case NFTNL_TYPE_U16:
 	case NFTNL_TYPE_U32:
 	case NFTNL_TYPE_U64:
-		uval = *((uint64_t *)val);
+		memcpy(&uval, val, sizeof(uval));
 		if (uval > basetype[type].max) {
 			errno = ERANGE;
 			return -1;
@@ -99,7 +99,7 @@ int nftnl_get_value(enum nftnl_type type, void *val, void *out)
 	case NFTNL_TYPE_S16:
 	case NFTNL_TYPE_S32:
 	case NFTNL_TYPE_S64:
-		sval = *((int64_t *)val);
+		memcpy(&sval, val, sizeof(sval));
 		if (sval < basetype[type].min ||
 		    sval > (int64_t)basetype[type].max) {
 			errno = ERANGE;
-- 
2.16.4




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux