mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-03 22:59:33 +00:00
LibELF: Fix unaligned writes in the relocation code
This commit is contained in:
parent
daeb371180
commit
ff292fbe5a
Notes:
sideshowbarker
2024-07-18 08:03:36 +09:00
Author: https://github.com/gunnarbeutner
Commit: ff292fbe5a
Pull-request: https://github.com/SerenityOS/serenity/pull/8962
1 changed files with 9 additions and 4 deletions
|
@ -53,10 +53,15 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
#else
|
||||
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE);
|
||||
#endif
|
||||
if (use_addend)
|
||||
*(FlatPtr*)(base_address + relocation->r_offset) = base_address + relocation->r_addend;
|
||||
else
|
||||
*(FlatPtr*)(base_address + relocation->r_offset) += base_address;
|
||||
auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset);
|
||||
FlatPtr relocated_address;
|
||||
if (use_addend) {
|
||||
relocated_address = base_address + relocation->r_addend;
|
||||
} else {
|
||||
__builtin_memcpy(&relocated_address, patch_address, sizeof(relocated_address));
|
||||
relocated_address += base_address;
|
||||
}
|
||||
__builtin_memcpy(patch_address, &relocated_address, sizeof(relocated_address));
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue