summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorNicholas Wilson <nicholas@nicholaswilson.me.uk>2018-03-02 14:35:29 +0000
committerNicholas Wilson <nicholas@nicholaswilson.me.uk>2018-03-02 14:35:29 +0000
commit3b82510523f6c7e985271acaa7fbce72ba990775 (patch)
tree8c3dffffd2ad3ec36d2902e71bbfefc747fd9c1b /llvm
parent9cc67133a147898183dd61164b972283c8358414 (diff)
downloadbcm5719-llvm-3b82510523f6c7e985271acaa7fbce72ba990775.tar.gz
bcm5719-llvm-3b82510523f6c7e985271acaa7fbce72ba990775.zip
[WebAssembly] Check function type indexes
Also update tests containing invalid Wasm files, exposed by the check Differential Revision: https://reviews.llvm.org/D43954 llvm-svn: 326577
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp7
-rw-r--r--llvm/test/ObjectYAML/wasm/export_section.yaml5
-rw-r--r--llvm/test/ObjectYAML/wasm/function_section.yaml9
3 files changed, 20 insertions, 1 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index b47d6bb2abb..491a4cf70ab 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -670,8 +670,13 @@ Error WasmObjectFile::parseImportSection(const uint8_t *Ptr, const uint8_t *End)
Error WasmObjectFile::parseFunctionSection(const uint8_t *Ptr, const uint8_t *End) {
uint32_t Count = readVaruint32(Ptr);
FunctionTypes.reserve(Count);
+ uint32_t NumTypes = Signatures.size();
while (Count--) {
- FunctionTypes.push_back(readVaruint32(Ptr));
+ uint32_t Type = readVaruint32(Ptr);
+ if (Type >= NumTypes)
+ return make_error<GenericBinaryError>("Invalid function type",
+ object_error::parse_failed);
+ FunctionTypes.push_back(Type);
}
if (Ptr != End)
return make_error<GenericBinaryError>("Function section ended prematurely",
diff --git a/llvm/test/ObjectYAML/wasm/export_section.yaml b/llvm/test/ObjectYAML/wasm/export_section.yaml
index 4dd62bde2c6..5e0d6d46a0d 100644
--- a/llvm/test/ObjectYAML/wasm/export_section.yaml
+++ b/llvm/test/ObjectYAML/wasm/export_section.yaml
@@ -3,6 +3,11 @@
FileHeader:
Version: 0x00000001
Sections:
+ - Type: TYPE
+ Signatures:
+ - Index: 0
+ ReturnType: NORESULT
+ ParamTypes:
- Type: FUNCTION
FunctionTypes: [ 0, 0 ]
- Type: GLOBAL
diff --git a/llvm/test/ObjectYAML/wasm/function_section.yaml b/llvm/test/ObjectYAML/wasm/function_section.yaml
index 571b762787a..0db0afd2d0e 100644
--- a/llvm/test/ObjectYAML/wasm/function_section.yaml
+++ b/llvm/test/ObjectYAML/wasm/function_section.yaml
@@ -3,6 +3,15 @@
FileHeader:
Version: 0x00000001
Sections:
+ - Type: TYPE
+ Signatures:
+ - Index: 0
+ ReturnType: NORESULT
+ ParamTypes:
+ - Index: 1
+ ReturnType: NORESULT
+ ParamTypes:
+ - I32
- Type: FUNCTION
FunctionTypes: [ 1, 0 ]
...
OpenPOWER on IntegriCloud