]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix runtime error: load of misaligned address in xlat_integer()
authorJorge Pereira <jpereiran@gmail.com>
Tue, 14 Mar 2023 18:44:21 +0000 (15:44 -0300)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 17 Mar 2023 13:24:53 +0000 (09:24 -0400)
Such error:

src/main/xlat.c:206:38: runtime error: load of misaligned address 0x00010410ba72 for type 'uint32_t' (aka 'unsigned int'), which requires 4 byte alignment
0x00010410ba72: note: pointer points here
 00 00  00 20 39 38 37 3e 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/main/xlat.c:206:38 in

src/main/xlat.c

index 8000aa15258aaf47cfe29c773c33d520575832a4..4bd0a379cb418e78e148b1fb171fdc3035788e8c 100644 (file)
@@ -203,7 +203,7 @@ static ssize_t xlat_integer(UNUSED void *instance, REQUEST *request,
                return snprintf(out, outlen, "%u", htonl(vp->vp_ipaddr));
 
        case PW_TYPE_IPV4_PREFIX:
-               return snprintf(out, outlen, "%u", htonl((*(uint32_t *)(vp->vp_ipv4prefix + 2))));
+               return snprintf(out, outlen, "%u", htonl((*(uint32_t *)(&vp->vp_ipv4prefix[2]))));
 
        case PW_TYPE_INTEGER:
                return snprintf(out, outlen, "%u", vp->vp_integer);