]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] Fix validation of start function
authorSam Clegg <sbc@chromium.org>
Tue, 9 May 2017 17:51:38 +0000 (17:51 +0000)
committerSam Clegg <sbc@chromium.org>
Tue, 9 May 2017 17:51:38 +0000 (17:51 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302560 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/WasmObjectFile.cpp
test/Object/wasm-invalid-start.test [new file with mode: 0644]
test/ObjectYAML/wasm/function_section.yaml
test/ObjectYAML/wasm/start_section.yaml

index 39f8704aacf2483b9f1ed647b6e93ce32ce9e843..012c9dccbe606659eb2a4e57a788b1d2dc115a49 100644 (file)
@@ -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/test/Object/wasm-invalid-start.test b/test/Object/wasm-invalid-start.test
new file mode 100644 (file)
index 0000000..12f7567
--- /dev/null
@@ -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
index 39e6b75d5cdcb93e5dacb08af22c7b0aaefa9982..571b762787a25147735fde548faaeb4bc732906e 100644 (file)
@@ -4,9 +4,7 @@ FileHeader:
   Version:         0x00000001
 Sections:
   - Type:            FUNCTION
-    FunctionTypes:   
-      - 1
-      - 0
+    FunctionTypes: [ 1, 0 ]
 ...
 # CHECK: --- !WASM
 # CHECK: FileHeader:
index 41301a6200377f0bc3d37b02e909eb81c9e7e47b..38feebcdf993ba498e5157ac1d9f9d3e3f63a129 100644 (file)
@@ -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
 ...