[llvm] r341343 - [NFC][llvm-objcopy] Fixing a ubi-san problem with unaligned memory writes.
Puyan Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 3 18:57:30 PDT 2018
Author: zer0
Date: Mon Sep 3 18:57:30 2018
New Revision: 341343
URL: http://llvm.org/viewvc/llvm-project?rev=341343&view=rev
Log:
[NFC][llvm-objcopy] Fixing a ubi-san problem with unaligned memory writes.
Modified:
llvm/trunk/tools/llvm-objcopy/Object.cpp
Modified: llvm/trunk/tools/llvm-objcopy/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.cpp?rev=341343&r1=341342&r2=341343&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/Object.cpp Mon Sep 3 18:57:30 2018
@@ -153,9 +153,10 @@ void ELFSectionWriter<ELFT>::visit(const
ArrayRef<uint8_t> Magic = {'Z', 'L', 'I', 'B'};
std::copy(Magic.begin(), Magic.end(), Buf);
Buf += Magic.size();
- uint64_t *DecompressedSizePtr = reinterpret_cast<uint64_t *>(Buf);
- *DecompressedSizePtr = support::endian::read64be(&Sec.DecompressedSize);
- Buf += sizeof(Sec.DecompressedSize);
+ const uint64_t DecompressedSize =
+ support::endian::read64be(&Sec.DecompressedSize);
+ memcpy(Buf, &DecompressedSize, sizeof(DecompressedSize));
+ Buf += sizeof(DecompressedSize);
} else {
auto Chdr = reinterpret_cast<Elf_Chdr_Impl<ELFT> *>(Buf);
Chdr->ch_type = ELF::ELFCOMPRESS_ZLIB;
More information about the llvm-commits
mailing list