From: Bob Haarman Date: Fri, 20 Apr 2018 22:16:09 +0000 (+0000) Subject: Fix nullptr passed to memcpy in lld/COFF/Chunks.cpp X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8679a7ecea9b630d7757075e18a4727a5d6a5fa5;p=platform%2Fupstream%2Fllvm.git Fix nullptr passed to memcpy in lld/COFF/Chunks.cpp 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 --- diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index a462caa..6d8a0c7 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -271,7 +271,8 @@ void SectionChunk::writeTo(uint8_t *Buf) const { return; // Copy section contents from source object file to output file. ArrayRef 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();