From 4710ed7a8ce3224c0d1fbb43748752513b0b6912 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Fri, 12 Jan 2018 02:11:31 +0000 Subject: [WebAssembly] Don't allow functions to be named twice The spec doesn't allow this. Differential Revision: https://reviews.llvm.org/D41974 llvm-svn: 322343 --- llvm/lib/Object/WasmObjectFile.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Object/WasmObjectFile.cpp') diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index ec2e2bf..60c87ca 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -8,6 +8,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" @@ -268,6 +269,8 @@ Error WasmObjectFile::parseSection(WasmSection &Sec) { } Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { + llvm::DenseSet Seen; + while (Ptr < End) { uint8_t Type = readVarint7(Ptr); uint32_t Size = readVaruint32(Ptr); @@ -277,6 +280,9 @@ Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { uint32_t Count = readVaruint32(Ptr); while (Count--) { uint32_t Index = readVaruint32(Ptr); + if (!Seen.insert(Index).second) + return make_error("Function named more than once", + object_error::parse_failed); StringRef Name = readString(Ptr); if (!Name.empty()) Symbols.emplace_back(Name, @@ -375,7 +381,6 @@ Error WasmObjectFile::parseLinkingSection(const uint8_t *Ptr, uint32_t Count = readVaruint32(Ptr); while (Count--) { StringRef Symbol = readString(Ptr); - DEBUG(dbgs() << "reading syminfo: " << Symbol << "\n"); uint32_t Flags = readVaruint32(Ptr); auto iter = SymbolMap.find(Symbol); if (iter == SymbolMap.end()) { -- cgit v1.1