summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-09-12 21:22:55 +0000
committerJustin Bogner <mail@justinbogner.com>2014-09-12 21:22:55 +0000
commit54b112828f8df04af8b7ab326d23789f2bea0389 (patch)
treeaa20e68132b8b7bc3ba1400e91a021d44778781c /llvm/lib/ProfileData
parent40bcd9f664d34de9e9038c0daad0021b7017d2c6 (diff)
downloadbcm5719-llvm-54b112828f8df04af8b7ab326d23789f2bea0389.tar.gz
bcm5719-llvm-54b112828f8df04af8b7ab326d23789f2bea0389.zip
llvm-profdata: Avoid undefined behaviour when reading raw profiles
The raw profiles that are generated in compiler-rt always add padding so that each profile is aligned, so we can simply treat files that don't have this property as malformed. Caught by Alexey's new ubsan bot. Thanks! llvm-svn: 217708
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/InstrProfReader.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp
index 5c1993766aa..e333473f6f8 100644
--- a/llvm/lib/ProfileData/InstrProfReader.cpp
+++ b/llvm/lib/ProfileData/InstrProfReader.cpp
@@ -190,6 +190,9 @@ RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
// garbage at the end of the file.
if (CurrentPos + sizeof(RawHeader) > End)
return instrprof_error::malformed;
+ // The writer ensures each profile is padded to start at an aligned address.
+ if (reinterpret_cast<size_t>(CurrentPos) % alignOf<uint64_t>())
+ return instrprof_error::malformed;
// The magic should have the same byte order as in the previous header.
uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);
if (Magic != swap(getRawMagic<IntPtrT>()))
OpenPOWER on IntegriCloud