From 8679a7ecea9b630d7757075e18a4727a5d6a5fa5 Mon Sep 17 00:00:00 2001 From: Bob Haarman Date: Fri, 20 Apr 2018 22:16:09 +0000 Subject: [PATCH] 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 --- lld/COFF/Chunks.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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(); -- 2.7.4