[llvm] r314368 - Fix a UBsan bot.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 17:27:39 PDT 2017


Author: ruiu
Date: Wed Sep 27 17:27:39 2017
New Revision: 314368

URL: http://llvm.org/viewvc/llvm-project?rev=314368&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/TarWriter.cpp

Modified: llvm/trunk/lib/Support/TarWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TarWriter.cpp?rev=314368&r1=314367&r2=314368&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TarWriter.cpp (original)
+++ llvm/trunk/lib/Support/TarWriter.cpp Wed Sep 27 17:27:39 2017
@@ -127,6 +127,7 @@ static void writePaxHeader(raw_fd_ostrea
 // Otherwise, returns false.
 static bool splitUstar(StringRef Path, StringRef &Prefix, StringRef &Name) {
   if (Path.size() < sizeof(UstarHeader::Name)) {
+    Prefix = "";
     Name = Path;
     return true;
   }




More information about the llvm-commits mailing list