summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/option-parser.c4
-rw-r--r--src/tools/wast2wasm.c38
-rw-r--r--src/validator.c122
-rw-r--r--src/validator.h14
4 files changed, 3 insertions, 175 deletions
diff --git a/src/option-parser.c b/src/option-parser.c
index 616c0462..fc680910 100644
--- a/src/option-parser.c
+++ b/src/option-parser.c
@@ -43,8 +43,10 @@ static int option_match(const char* s,
return -1;
break;
}
- if (s[i] != full[i])
+ if (s[i] == '\0')
break;
+ if (s[i] != full[i])
+ return -1;
}
return i;
}
diff --git a/src/tools/wast2wasm.c b/src/tools/wast2wasm.c
index 6a2e60bf..e0c8c1de 100644
--- a/src/tools/wast2wasm.c
+++ b/src/tools/wast2wasm.c
@@ -46,7 +46,6 @@ static WasmWriteBinarySpecOptions s_write_binary_spec_options =
static WasmBool s_spec;
static WasmBool s_use_libc_allocator;
static WasmBool s_validate = WASM_TRUE;
-static WasmBool s_validate_assert_invalid_and_malformed = WASM_TRUE;
static WasmSourceErrorHandler s_error_handler =
WASM_SOURCE_ERROR_HANDLER_DEFAULT;
@@ -67,7 +66,6 @@ enum {
FLAG_NO_CANONICALIZE_LEB128S,
FLAG_DEBUG_NAMES,
FLAG_NO_CHECK,
- FLAG_NO_CHECK_ASSERT_INVALID_AND_MALFORMED,
NUM_FLAGS
};
@@ -110,9 +108,6 @@ static WasmOption s_options[] = {
"Write debug names to the generated binary file"},
{FLAG_NO_CHECK, 0, "no-check", NULL, NOPE,
"Don't check for invalid modules"},
- {FLAG_NO_CHECK_ASSERT_INVALID_AND_MALFORMED, 0,
- "no-check-assert-invalid-and-malformed", NULL, NOPE,
- "Don't run the assert_invalid or assert_malformed checks"},
};
WASM_STATIC_ASSERT(NUM_FLAGS == WASM_ARRAY_SIZE(s_options));
@@ -161,10 +156,6 @@ static void on_option(struct WasmOptionParser* parser,
case FLAG_NO_CHECK:
s_validate = WASM_FALSE;
break;
-
- case FLAG_NO_CHECK_ASSERT_INVALID_AND_MALFORMED:
- s_validate_assert_invalid_and_malformed = WASM_FALSE;
- break;
}
}
@@ -207,18 +198,6 @@ static void write_buffer_to_file(const char* filename,
}
}
-static void init_source_error_handler(WasmSourceErrorHandler* error_handler,
- WasmDefaultErrorHandlerInfo* info,
- const char* header) {
- info->header = header;
- info->out_file = stdout;
- info->print_header = WASM_PRINT_ERROR_HEADER_ALWAYS;
-
- error_handler->on_error = wasm_default_source_error_callback;
- error_handler->source_line_max_length = WASM_SOURCE_LINE_MAX_LENGTH_DEFAULT;
- error_handler->user_data = info;
-}
-
int main(int argc, char** argv) {
WasmStackAllocator stack_allocator;
WasmAllocator* allocator;
@@ -251,23 +230,6 @@ int main(int argc, char** argv) {
wasm_validate_script(allocator, lexer, &script, &s_error_handler);
}
- if (WASM_SUCCEEDED(result) && s_validate_assert_invalid_and_malformed) {
- WasmDefaultErrorHandlerInfo assert_invalid_info;
- WasmSourceErrorHandler assert_invalid_error_handler;
- init_source_error_handler(&assert_invalid_error_handler,
- &assert_invalid_info, "assert_invalid error");
-
- WasmDefaultErrorHandlerInfo assert_malformed_info;
- WasmSourceErrorHandler assert_malformed_error_handler;
- init_source_error_handler(&assert_malformed_error_handler,
- &assert_malformed_info,
- "assert_malformed error");
-
- result = wasm_validate_assert_invalid_and_malformed(
- allocator, lexer, &script, &assert_invalid_error_handler,
- &assert_malformed_error_handler, &s_error_handler);
- }
-
if (WASM_SUCCEEDED(result)) {
if (s_spec) {
s_write_binary_spec_options.json_filename = s_outfile;
diff --git a/src/validator.c b/src/validator.c
index 52ca4317..ba49296a 100644
--- a/src/validator.c
+++ b/src/validator.c
@@ -1118,70 +1118,6 @@ static void check_module(Context* ctx, const WasmModule* module) {
check_duplicate_export_bindings(ctx, module);
}
-typedef struct BinaryErrorCallbackData {
- Context* ctx;
- WasmLocation* loc;
-} BinaryErrorCallbackData;
-
-static void on_read_binary_error(uint32_t offset,
- const char* error,
- void* user_data) {
- BinaryErrorCallbackData* data = user_data;
- if (offset == WASM_UNKNOWN_OFFSET) {
- print_error(data->ctx, data->loc, "error in binary module: %s", error);
- } else {
- print_error(data->ctx, data->loc, "error in binary module: @0x%08x: %s",
- offset, error);
- }
-}
-
-typedef struct ReadModule {
- WasmModule module;
- WasmBool owned;
-} ReadModule;
-
-static void destroy_read_module(WasmAllocator* allocator,
- ReadModule* read_module) {
- if (read_module->owned)
- wasm_destroy_module(allocator, &read_module->module);
-}
-
-static WasmResult read_raw_module(Context* ctx,
- WasmRawModule* raw,
- ReadModule* out_module) {
- if (raw->type != WASM_RAW_MODULE_TYPE_BINARY) {
- out_module->module = *raw->text;
- out_module->owned = WASM_FALSE;
- return WASM_OK;
- }
-
- WASM_ZERO_MEMORY(*out_module);
- WasmReadBinaryOptions options = WASM_READ_BINARY_OPTIONS_DEFAULT;
- BinaryErrorCallbackData user_data;
- user_data.ctx = ctx;
- user_data.loc = &raw->binary.loc;
- WasmBinaryErrorHandler error_handler;
- error_handler.on_error = on_read_binary_error;
- error_handler.user_data = &user_data;
- WasmResult result =
- wasm_read_binary_ast(ctx->allocator, raw->binary.data, raw->binary.size,
- &options, &error_handler, &out_module->module);
- out_module->owned = WASM_SUCCEEDED(result);
- return result;
-}
-
-static void check_raw_module(Context* ctx, WasmRawModule* raw) {
- ReadModule read_module;
- if (WASM_SUCCEEDED(read_raw_module(ctx, raw, &read_module))) {
- WasmModule* module = &read_module.module;
- ctx->result = wasm_resolve_names_module(ctx->allocator, ctx->lexer, module,
- ctx->error_handler);
- if (WASM_SUCCEEDED(ctx->result))
- check_module(ctx, module);
- }
- destroy_read_module(ctx->allocator, &read_module);
-}
-
/* returns the result type of the invoked function, checked by the caller;
* returning NULL means that another error occured first, so the result type
* should be ignored. */
@@ -1378,61 +1314,3 @@ WasmResult wasm_validate_script(WasmAllocator* allocator,
wasm_destroy_context(&ctx);
return ctx.result;
}
-
-WasmResult wasm_validate_assert_invalid_and_malformed(
- WasmAllocator* allocator,
- WasmAstLexer* lexer,
- const struct WasmScript* script,
- WasmSourceErrorHandler* assert_invalid_error_handler,
- WasmSourceErrorHandler* assert_malformed_error_handler,
- WasmSourceErrorHandler* error_handler) {
- Context ctx;
- WASM_ZERO_MEMORY(ctx);
- ctx.allocator = allocator;
- ctx.lexer = lexer;
- ctx.error_handler = error_handler;
- ctx.result = WASM_OK;
- ctx.script = script;
-
- size_t i;
- for (i = 0; i < script->commands.size; ++i) {
- WasmCommand* command = &script->commands.data[i];
- if (command->type != WASM_COMMAND_TYPE_ASSERT_INVALID &&
- command->type != WASM_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY &&
- command->type != WASM_COMMAND_TYPE_ASSERT_MALFORMED) {
- continue;
- }
-
- Context ctx2;
- WASM_ZERO_MEMORY(ctx2);
- ctx2.allocator = allocator;
- ctx2.lexer = lexer;
- ctx2.result = WASM_OK;
- ctx2.script = script;
-
- if (command->type == WASM_COMMAND_TYPE_ASSERT_INVALID ||
- command->type == WASM_COMMAND_TYPE_ASSERT_INVALID_NON_BINARY) {
- ctx2.error_handler = assert_invalid_error_handler;
- check_raw_module(&ctx2, &command->assert_invalid.module);
- wasm_destroy_context(&ctx2);
- if (WASM_SUCCEEDED(ctx2.result)) {
- print_error(
- &ctx, wasm_get_raw_module_location(&command->assert_invalid.module),
- "expected module to be invalid");
- }
- } else if (command->type == WASM_COMMAND_TYPE_ASSERT_MALFORMED) {
- ctx2.error_handler = assert_malformed_error_handler;
- ReadModule read_module;
- read_raw_module(&ctx2, &command->assert_malformed.module, &read_module);
- destroy_read_module(ctx.allocator, &read_module);
- wasm_destroy_context(&ctx2);
- if (WASM_SUCCEEDED(ctx2.result)) {
- print_error(&ctx, wasm_get_raw_module_location(
- &command->assert_malformed.module),
- "expected module to be malformed");
- }
- }
- }
- wasm_destroy_context(&ctx);
- return ctx.result;
-}
diff --git a/src/validator.h b/src/validator.h
index 5d6ea590..d6f29d27 100644
--- a/src/validator.h
+++ b/src/validator.h
@@ -32,18 +32,4 @@ WasmResult wasm_validate_script(struct WasmAllocator*,
const struct WasmScript*,
WasmSourceErrorHandler*);
-/* Run the assert_invalid and assert_malformed spec tests. A module is
- * "malformed" if it cannot be read from the binary format. A module is
- * "invalid" if either it is malformed, or if it does not pass the standard
- * checks (as done by wasm_validate_script). This function succeeds if and only
- * if all assert_invalid and assert_malformed tests pass. */
-WasmResult wasm_validate_assert_invalid_and_malformed(
- struct WasmAllocator*,
- WasmAstLexer*,
- const struct WasmScript*,
- WasmSourceErrorHandler* assert_invalid_error_handler,
- WasmSourceErrorHandler* assert_malformed_error_handler,
- WasmSourceErrorHandler* error_handler);
-WASM_EXTERN_C_END
-
#endif /* WASM_VALIDATOR_H_ */