Skip to content

Commit

Permalink
Fix nullptr passed to memcpy in lld/COFF/Chunks.cpp
Browse files Browse the repository at this point in the history
Summary:
ubsan found that we sometimes pass nullptr to memcpy in
SectionChunk::writeTo(). This change adds a check that avoids that.

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45789

llvm-svn: 330490
  • Loading branch information
inglorion committed Apr 20, 2018
1 parent 106df7d commit 8679a7e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lld/COFF/Chunks.cpp
Expand Up @@ -271,7 +271,8 @@ void SectionChunk::writeTo(uint8_t *Buf) const {
return;
// Copy section contents from source object file to output file.
ArrayRef<uint8_t> A = getContents();
memcpy(Buf + OutputSectionOff, A.data(), A.size());
if (!A.empty())
memcpy(Buf + OutputSectionOff, A.data(), A.size());

// Apply relocations.
size_t InputSize = getSize();
Expand Down

0 comments on commit 8679a7e

Please sign in to comment.