summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Object/WasmObjectFile.cpp
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2018-08-08 16:34:03 +0000
committerJonas Devlieghere <jonas@devlieghere.com>2018-08-08 16:34:03 +0000
commit8511777d3a41e5198a7028711754d3e9c29afddc (patch)
tree01199be05c675f202346c8f6215297eecb8acabf /llvm/lib/Object/WasmObjectFile.cpp
parentcaacedb03e95fb02cad30b0d53eb52494a543674 (diff)
downloadbcm5719-llvm-8511777d3a41e5198a7028711754d3e9c29afddc.tar.gz
bcm5719-llvm-8511777d3a41e5198a7028711754d3e9c29afddc.zip
[WASM] Fix overflow when reading custom section
When reading a custom WASM section, it was possible that its name extended beyond the size of the section. This resulted in a bogus value for the section size due to the size overflowing. Fixes heap buffer overflow detected by OSS-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8190 Differential revision: https://reviews.llvm.org/D50387 llvm-svn: 339269
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 4d4c887b2d9..1b32ae8afd9 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -216,9 +216,16 @@ static Error readSection(WasmSection &Section,
return make_error<StringError>("Section too large",
object_error::parse_failed);
if (Section.Type == wasm::WASM_SEC_CUSTOM) {
- const uint8_t *NameStart = Ctx.Ptr;
- Section.Name = readString(Ctx);
- Size -= Ctx.Ptr - NameStart;
+ WasmObjectFile::ReadContext SectionCtx;
+ SectionCtx.Start = Ctx.Ptr;
+ SectionCtx.Ptr = Ctx.Ptr;
+ SectionCtx.End = Ctx.Ptr + Size;
+
+ Section.Name = readString(SectionCtx);
+
+ uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start;
+ Ctx.Ptr += SectionNameSize;
+ Size -= SectionNameSize;
}
Section.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size);
Ctx.Ptr += Size;
OpenPOWER on IntegriCloud