]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix alignment issue
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 17 Mar 2021 11:35:30 +0000 (11:35 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 17 Mar 2021 11:35:51 +0000 (11:35 +0000)
src/include/missing-h
src/lib/unlang/xlat_builtin.c
src/lib/util/missing.c

index 912f6b761d86d68ea25f5af7f37a916df827ff84..0d1d469b49f82d96b7c73ae2b6bf138292d438c7 100644 (file)
@@ -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 *) &num;
+       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)
index bd44becb1da3909a5b34338ec992f664fc8dd9de..4738e1688d73bdac57d7c8b4ae53907c052766f9 100644 (file)
@@ -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;
index 933fae800292fce1f607b8caa43cba50783a9b1e..e918b34e28238a5f2be9515726b719803a465ff3 100644 (file)
@@ -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 *) &num;
-       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
  */