Parcourir la source

wasm_runtime.c: Fix fault modification on data segment (#1116)

Fix fault modification on data segment in wasm module which leads to
fail to instantiate wasm module next time, reported by #1115.

Co-authored-by: yangwenming <yangwenming@bytedance.com>
YoungWenMing il y a 3 ans
Parent
commit
5f8d1428d5
1 fichiers modifiés avec 4 ajouts et 2 suppressions
  1. 4 2
      core/iwasm/interpreter/wasm_runtime.c

+ 4 - 2
core/iwasm/interpreter/wasm_runtime.c

@@ -1333,12 +1333,14 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size,
                 goto fail;
             }
 
-            data_seg->base_offset.u.i32 =
+            base_offset =
                 globals[data_seg->base_offset.u.global_index].initial_value.i32;
         }
+        else {
+            base_offset = (uint32)data_seg->base_offset.u.i32;
+        }
 
         /* check offset */
-        base_offset = (uint32)data_seg->base_offset.u.i32;
         if (base_offset > memory_size) {
             LOG_DEBUG("base_offset(%d) > memory_size(%d)", base_offset,
                       memory_size);