From: Arran Cudbard-Bell Date: Wed, 17 Mar 2021 11:35:30 +0000 (+0000) Subject: Fix alignment issue X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ccc9e709672a4b4ee9cb5dd834a90ee319a269ea;p=thirdparty%2Ffreeradius-server.git Fix alignment issue --- diff --git a/src/include/missing-h b/src/include/missing-h index 912f6b761d8..0d1d469b49f 100644 --- a/src/include/missing-h +++ b/src/include/missing-h @@ -501,7 +501,17 @@ typedef struct { # ifdef HAVE_128BIT_INTEGERS # define ntohlll(x) (((uint128_t)ntohll((uint64_t)(x >> 64))) | (((uint128_t)ntohll(((uint64_t) x)) << 64))) # else -uint128_t ntohlll(uint128_t num); +static inline uint128_t ntohlll(uint128_t const num) +{ + uint64_t const *p = (uint64_t const *) # + uint64_t ret[2]; + + /* swapsies */ + ret[1] = ntohll(p[0]); + ret[0] = ntohll(p[1]); + + return *(uint128_t *)ret; +} # endif # else # define ntohlll(x) (x) diff --git a/src/lib/unlang/xlat_builtin.c b/src/lib/unlang/xlat_builtin.c index bd44becb1da..4738e1688d7 100644 --- a/src/lib/unlang/xlat_builtin.c +++ b/src/lib/unlang/xlat_builtin.c @@ -1266,7 +1266,16 @@ static ssize_t xlat_func_integer(UNUSED TALLOC_CTX *ctx, char **out, size_t outl case FR_TYPE_IPV6_ADDR: case FR_TYPE_IPV6_PREFIX: - return fr_snprint_uint128(*out, outlen, ntohlll(*(uint128_t const *) &vp->vp_ipv6addr)); + { + uint128_t ipv6int; + + /* + * Needed for correct alignment (as flagged by ubsan) + */ + memcpy(&ipv6int, &vp->vp_ipv6addr, sizeof(ipv6int)); + + return fr_snprint_uint128(*out, outlen, ntohlll(ipv6int)); + } default: break; diff --git a/src/lib/util/missing.c b/src/lib/util/missing.c index 933fae80029..e918b34e282 100644 --- a/src/lib/util/missing.c +++ b/src/lib/util/missing.c @@ -269,25 +269,6 @@ int clock_gettime(int clk_id, struct timespec *t) } #endif -#if !defined(HAVE_128BIT_INTEGERS) && !defined(WORDS_BIGENDIAN) -/** Swap byte order of 128 bit integer - * - * @param num 128bit integer to swap. - * @return 128bit integer reversed. - */ -uint128_t ntohlll(uint128_t const num) -{ - uint64_t const *p = (uint64_t const *) # - uint64_t ret[2]; - - /* swapsies */ - ret[1] = ntohll(p[0]); - ret[0] = ntohll(p[1]); - - return *(uint128_t *)ret; -} -#endif - /* * Replacements in case we don't have inet_pton */