From a1f46fe51cd4d10d1b4714e6887bf8cc4cee1a47 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Sat, 20 Apr 2019 00:11:46 +0000 Subject: [PATCH] [WebAssembly] Object: Improve error messages on invalid section Also add a test. Differential Revision: https://reviews.llvm.org/D60836 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358801 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Object/WasmObjectFile.cpp | 6 +++--- test/Object/wasm-invalid-file.yaml | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp index 167b8c25c2b..45e343f8f47 100644 --- a/lib/Object/WasmObjectFile.cpp +++ b/lib/Object/WasmObjectFile.cpp @@ -319,8 +319,8 @@ Error WasmObjectFile::parseSection(WasmSection &Sec) { case wasm::WASM_SEC_DATACOUNT: return parseDataCountSection(Ctx); default: - return make_error("Bad section type", - object_error::parse_failed); + return make_error( + "Invalid section type: " + Twine(Sec.Type), object_error::parse_failed); } } @@ -1607,7 +1607,7 @@ int WasmSectionOrderChecker::getSectionOrder(unsigned ID, case wasm::WASM_SEC_EVENT: return WASM_SEC_ORDER_EVENT; default: - llvm_unreachable("invalid section"); + return WASM_SEC_ORDER_NONE; } } diff --git a/test/Object/wasm-invalid-file.yaml b/test/Object/wasm-invalid-file.yaml index 309fbd46e6e..e562dfaa815 100644 --- a/test/Object/wasm-invalid-file.yaml +++ b/test/Object/wasm-invalid-file.yaml @@ -14,3 +14,9 @@ FileHeader: # RUN: not llvm-objdump -h %t.wasm 2>&1 | FileCheck %s -check-prefix=CHECK-SECTION-SIZE # CHECK-SECTION-SIZE: '{{.*}}.wasm': Section too large + +# RUN: yaml2obj %s > %t.wasm +# # Append an section with invalid type (type 0x20, size 0x1, content 0x0) +# RUN: echo -e -n "\x20\x01\x00" >> %t.wasm +# RUN: not llvm-objdump -h %t.wasm 2>&1 | FileCheck %s -check-prefix=CHECK-SECTION-TYPE +# CHECK-SECTION-TYPE: '{{.*}}.wasm': Invalid section type: 32 -- 2.50.1