summaryrefslogtreecommitdiffstats
path: root/src/expr/hash.c
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2018-10-17 12:32:54 -0700
committerPablo Neira Ayuso <pablo@netfilter.org>2018-10-19 14:56:08 +0200
commitdc240913458d591f59b52b3899d3fc3c5d6ec6ce (patch)
treeb43acfe0306f2ab42a5f5abccc42420fe6a5508c /src/expr/hash.c
parentaecc936180d302947ecfab5dacf267a701a5d84c (diff)
src: Use memcpy() to handle potentially unaligned data
Rolf Eike Beer <eike@sf-mail.de> 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@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/expr/hash.c')
-rw-r--r--src/expr/hash.c16
1 files changed, 8 insertions, 8 deletions
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;