]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
x86_64: Fix UB on plt rewrite
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 18 Apr 2025 12:49:59 +0000 (09:49 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:20 +0000 (14:21 -0300)
The elf/tst-plt-rewrite2 and elf/tst-plt-rewrite2 triggers the
failures with ubsan:

UBSAN: Undefined behaviour in ../sysdeps/x86_64/dl-machine.h:637:39 store to misaligned address 0x00007adb50230021 for type 'uint32_t'

sysdeps/x86_64/dl-machine.h

index 572a1a7395da0480ab1b980da57893ab74b95992..3799894589cd866a4a46fde8f3c2c6f804bd24dd 100644 (file)
@@ -633,7 +633,7 @@ x86_64_rewrite_plt (struct link_map *map, ElfW(Addr) plt_rewrite)
 
            /* Write out direct branch.  */
            *(uint8_t *) branch_start = JMP32_INSN_OPCODE;
-           *(uint32_t *) (branch_start + 1) = disp;
+           memcpy ((void *)(branch_start + 1), &disp, sizeof (uint32_t));
          }
        else
          {