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