From dc240913458d591f59b52b3899d3fc3c5d6ec6ce Mon Sep 17 00:00:00 2001 From: Matt Turner Date: Wed, 17 Oct 2018 12:32:54 -0700 Subject: src: Use memcpy() to handle potentially unaligned data Rolf Eike Beer 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 Signed-off-by: Pablo Neira Ayuso --- src/expr/hash.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/expr/hash.c') 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; -- cgit v1.2.3