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/utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils.c') 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; -- cgit v1.2.3