[lld] r263919 - [COFF] Don't call memcpy with a NULL argument
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 20 16:10:12 PDT 2016
Author: majnemer
Date: Sun Mar 20 18:10:12 2016
New Revision: 263919
URL: http://llvm.org/viewvc/llvm-project?rev=263919&view=rev
Log:
[COFF] Don't call memcpy with a NULL argument
Some declarations of memcpy (like glibc's for example) are attributed
with notnull which makes it UB for NULL to get passed in, even if the
memcpy count is zero.
To account for this, guard the memcpy with an appropriate precondition.
This should fix the last UBSan bug, exposed by the test suite, in the
COFF linker.
Modified:
lld/trunk/COFF/Writer.cpp
Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=263919&r1=263918&r2=263919&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Sun Mar 20 18:10:12 2016
@@ -639,7 +639,8 @@ template <typename PEHeaderTy> void Writ
// The first 4 bytes is length including itself.
Buf = reinterpret_cast<uint8_t *>(&SymbolTable[NumberOfSymbols]);
write32le(Buf, Strtab.size() + 4);
- memcpy(Buf + 4, Strtab.data(), Strtab.size());
+ if (!Strtab.empty())
+ memcpy(Buf + 4, Strtab.data(), Strtab.size());
}
void Writer::openFile(StringRef Path) {
More information about the llvm-commits
mailing list