diff options
author | Sam Clegg <sbc@chromium.org> | 2017-05-09 17:51:38 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-05-09 17:51:38 +0000 |
commit | a0efcfe92b9e12be83c80878ce83e18fe8234c3d (patch) | |
tree | 41776d1630092ce30107c9a9906daa85e1f07610 | |
parent | 073c4e66b01d8f9f66a1c7b660d926a8b2748665 (diff) | |
download | bcm5719-llvm-a0efcfe92b9e12be83c80878ce83e18fe8234c3d.tar.gz bcm5719-llvm-a0efcfe92b9e12be83c80878ce83e18fe8234c3d.zip |
[WebAssembly] Fix validation of start function
The check for valid start function was inverted. Added a new
test in test/Object to check this case and fixed the existing
tests in for ObjectYAML.
Differential Revision: https://reviews.llvm.org/D32986
llvm-svn: 302560
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Object/wasm-invalid-start.test | 10 | ||||
-rw-r--r-- | llvm/test/ObjectYAML/wasm/function_section.yaml | 4 | ||||
-rw-r--r-- | llvm/test/ObjectYAML/wasm/start_section.yaml | 9 |
4 files changed, 21 insertions, 4 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 39f8704aacf..012c9dccbe6 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -507,7 +507,7 @@ Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End) Error WasmObjectFile::parseStartSection(const uint8_t *Ptr, const uint8_t *End) { StartFunction = readVaruint32(Ptr); - if (StartFunction < FunctionTypes.size()) + if (StartFunction >= FunctionTypes.size()) return make_error<GenericBinaryError>("Invalid start function", object_error::parse_failed); return Error::success(); diff --git a/llvm/test/Object/wasm-invalid-start.test b/llvm/test/Object/wasm-invalid-start.test new file mode 100644 index 00000000000..12f75676345 --- /dev/null +++ b/llvm/test/Object/wasm-invalid-start.test @@ -0,0 +1,10 @@ +# RUN: yaml2obj %s | not llvm-objdump -h - 2>&1 | FileCheck %s + +!WASM +FileHeader: + Version: 0x00000001 +Sections: + - Type: START + StartFunction: 0 + +# CHECK: {{.*}}: Invalid start function diff --git a/llvm/test/ObjectYAML/wasm/function_section.yaml b/llvm/test/ObjectYAML/wasm/function_section.yaml index 39e6b75d5cd..571b762787a 100644 --- a/llvm/test/ObjectYAML/wasm/function_section.yaml +++ b/llvm/test/ObjectYAML/wasm/function_section.yaml @@ -4,9 +4,7 @@ FileHeader: Version: 0x00000001 Sections: - Type: FUNCTION - FunctionTypes: - - 1 - - 0 + FunctionTypes: [ 1, 0 ] ... # CHECK: --- !WASM # CHECK: FileHeader: diff --git a/llvm/test/ObjectYAML/wasm/start_section.yaml b/llvm/test/ObjectYAML/wasm/start_section.yaml index 41301a62003..38feebcdf99 100644 --- a/llvm/test/ObjectYAML/wasm/start_section.yaml +++ b/llvm/test/ObjectYAML/wasm/start_section.yaml @@ -1,8 +1,17 @@ # RUN: yaml2obj %s | obj2yaml | FileCheck %s + --- !WASM FileHeader: Version: 0x00000001 Sections: + - Type: TYPE + Signatures: + - ReturnType: I32 + ParamTypes: + - F32 + - F32 + - Type: FUNCTION + FunctionTypes: [ 0, 0, 0 ] - Type: START StartFunction: 1 ... |