Add more checks about the imports of wasm_instance_new (#1843)

Check whether the `imports` argument is NULL in wasm_instance_new and check
the import count of each kind.

Fix issue reported by https://github.com/bytecodealliance/wasm-micro-runtime/issues/1833
This commit is contained in:
liang.he
2023-01-03 17:16:49 +08:00
committed by GitHub
parent d5aa354d41
commit bf2be805f9
3 changed files with 102 additions and 63 deletions

View File

@ -159,6 +159,9 @@ endif()
check_pie_supported()
include(CTest)
enable_testing()
foreach(EX ${EXAMPLES})
set(SRC ${CMAKE_CURRENT_LIST_DIR}/src/${EX}.c)
@ -193,6 +196,12 @@ foreach(EX ${EXAMPLES})
)
add_dependencies(${EX} ${EX}_AOT)
endif()
# run `ctest --test-dir build`
add_test(NAME Test_${EX}
COMMAND ./${EX}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
@ -201,19 +210,5 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
REQUIRED
)
if(VALGRIND)
foreach(EX ${EXAMPLES})
add_custom_command(
OUTPUT ${EX}_leak_check.report
DEPENDS ${EX} ${EX}_WASM
COMMAND ${VALGRIND} --tool=memcheck --leak-check=full -- ./${EX} > ${EX}_leak_check.report 2>&1
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
add_custom_target(${EX}_LEAK_TEST ALL
DEPENDS ${EX}_leak_check.report
COMMAND grep "All heap blocks were freed -- no leaks are possible" ${EX}_leak_check.report
COMMENT "Please read ${EX}_leak_check.report when meeting Error"
)
endforeach()
endif (VALGRIND)
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
# run `ctest -T memcheck -V --test-dir build`
endif()

View File

@ -238,7 +238,7 @@ main(int argc, const char *argv[])
IMPORT_FUNCTION_LIST(CREATE_WASM_FUNCTION)
#undef CREATE_WASM_FUNCTION
wasm_extern_t *fs[10] = { 0 };
wasm_extern_t *fs[2] = { 0 };
#define ADD_TO_FUNCTION_LIST(name, index, ...) \
fs[index] = wasm_func_as_extern(function_##name);
IMPORT_FUNCTION_LIST(ADD_TO_FUNCTION_LIST)