diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/apply-names.c | 5 | ||||
-rw-r--r-- | src/binary-reader-ast.c | 9 | ||||
-rw-r--r-- | src/binary-reader.c | 13 | ||||
-rw-r--r-- | src/tools/wasm2wast.c | 8 |
4 files changed, 22 insertions, 13 deletions
diff --git a/src/apply-names.c b/src/apply-names.c index 133808df..23ba7c1a 100644 --- a/src/apply-names.c +++ b/src/apply-names.c @@ -134,8 +134,9 @@ static WasmResult use_name_for_param_and_local_var(Context* ctx, WasmFunc* func, WasmVar* var) { int local_index = wasm_get_local_index_by_var(func, var); - assert(local_index >= 0 && - (size_t)local_index < wasm_get_num_params_and_locals(func)); + if (local_index < 0 || + (size_t)local_index >= wasm_get_num_params_and_locals(func)) + return WASM_ERROR; uint32_t num_params = wasm_get_num_params(func); WasmStringSlice* name; diff --git a/src/binary-reader-ast.c b/src/binary-reader-ast.c index 68c49be7..22b71d9f 100644 --- a/src/binary-reader-ast.c +++ b/src/binary-reader-ast.c @@ -90,8 +90,8 @@ static WasmResult pop_label(Context* ctx) { static WasmResult get_label_at(Context* ctx, LabelNode** label, uint32_t depth) { - if (depth > ctx->label_stack.size) { - print_error(ctx, "accessing stack depth: %u > max: %" PRIzd, depth, + if (depth >= ctx->label_stack.size) { + print_error(ctx, "accessing stack depth: %u >= max: %" PRIzd, depth, ctx->label_stack.size); return WASM_ERROR; } @@ -116,7 +116,10 @@ static void dup_name(Context* ctx, static WasmResult append_expr(Context* ctx, WasmExpr* expr) { LabelNode* label; - CHECK_RESULT(top_label(ctx, &label)); + if (WASM_FAILED(top_label(ctx, &label))) { + wasm_free(ctx->allocator, expr); + return WASM_ERROR; + } if (*label->first) { label->last->next = expr; label->last = expr; diff --git a/src/binary-reader.c b/src/binary-reader.c index 028ef99f..9223935a 100644 --- a/src/binary-reader.c +++ b/src/binary-reader.c @@ -122,7 +122,7 @@ typedef struct Context { WasmTypeVector param_types; Uint32Vector target_depths; const WasmReadBinaryOptions* options; - WasmBinarySection last_section_code; + WasmBinarySection last_known_section_code; uint32_t num_signatures; uint32_t num_imports; uint32_t num_func_imports; @@ -1643,7 +1643,7 @@ static void read_custom_section(Context* ctx, uint32_t section_size) { CALLBACK_CTX(begin_custom_section, section_size, section_name); WasmBool name_section_ok = - ctx->last_section_code >= WASM_BINARY_SECTION_IMPORT; + ctx->last_known_section_code >= WASM_BINARY_SECTION_IMPORT; if (ctx->options->read_debug_names && name_section_ok && strncmp(section_name.start, WASM_BINARY_SECTION_NAME, section_name.length) == 0) { @@ -1997,9 +1997,9 @@ static void read_sections(Context* ctx) { if (ctx->read_end > ctx->data_size) RAISE_ERROR("invalid section size: extends past end"); - if (ctx->last_section_code != WASM_NUM_BINARY_SECTIONS && + if (ctx->last_known_section_code != WASM_NUM_BINARY_SECTIONS && section_code != WASM_BINARY_SECTION_CUSTOM && - section_code <= ctx->last_section_code) { + section_code <= ctx->last_known_section_code) { RAISE_ERROR("section %s out of order", s_section_name[section_code]); } @@ -2024,7 +2024,8 @@ static void read_sections(Context* ctx) { ctx->read_end); } - ctx->last_section_code = section_code; + if (section_code != WASM_BINARY_SECTION_CUSTOM) + ctx->last_known_section_code = section_code; } } @@ -2051,7 +2052,7 @@ WasmResult wasm_read_binary(WasmAllocator* allocator, ctx->data_size = ctx->read_end = size; ctx->reader = options->log_stream ? &logging_reader : reader; ctx->options = options; - ctx->last_section_code = WASM_NUM_BINARY_SECTIONS; + ctx->last_known_section_code = WASM_NUM_BINARY_SECTIONS; if (setjmp(ctx->error_jmp_buf) == 1) { destroy_context(ctx); diff --git a/src/tools/wasm2wast.c b/src/tools/wasm2wast.c index 55050f96..05ddcf77 100644 --- a/src/tools/wasm2wast.c +++ b/src/tools/wasm2wast.c @@ -173,8 +173,12 @@ int main(int argc, char** argv) { if (s_generate_names) result = wasm_generate_names(allocator, &module); - if (WASM_SUCCEEDED(result)) - result = wasm_apply_names(allocator, &module); + if (WASM_SUCCEEDED(result)) { + /* TODO(binji): This shouldn't fail; if a name can't be applied + * (because the index is invalid, say) it should just be skipped. */ + WasmResult dummy_result = wasm_apply_names(allocator, &module); + WASM_USE(dummy_result); + } if (WASM_SUCCEEDED(result)) { WasmFileWriter file_writer; |