From 5908845a7e7c6db39e100246a3875f519f5d1f97 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 28 Sep 2017 00:27:39 +0000 Subject: [PATCH] Fix a UBsan bot. If we do not initialize Prefix here, Prefix.data() returns a nullptr. Later, it is passed to memcpy. memcpy's behavior is undefined if src (or dst) is a nullptr even if a given size is 0. That's why this code triggered UBsan. llvm-svn: 314368 --- llvm/lib/Support/TarWriter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Support/TarWriter.cpp b/llvm/lib/Support/TarWriter.cpp index 5ae6474..5009607 100644 --- a/llvm/lib/Support/TarWriter.cpp +++ b/llvm/lib/Support/TarWriter.cpp @@ -127,6 +127,7 @@ static void writePaxHeader(raw_fd_ostream &OS, StringRef Path) { // Otherwise, returns false. static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name) { if (Path.size() < sizeof(UstarHeader::Name)) { + Prefix = ""; Name = Path; return true; } -- 2.7.4