From 121232a9957a069bbb04ebda053bdc72ab409e7a Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Sun, 27 Jul 2025 14:38:56 +0800 Subject: [PATCH] Merge commit from fork If `--addr-pool=1.2.3.4`, the runtime will return an error. The value must be in the form of ADDRESS/MASK. --- core/iwasm/common/wasm_runtime_common.c | 10 +++++++++- doc/socket_api.md | 3 ++- product-mini/platforms/common/libc_wasi.c | 2 +- samples/socket-api/CMakeLists.txt | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index b32110272..943b46fc4 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -3810,7 +3810,15 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst, address = strtok(cp, "/"); mask = strtok(NULL, "/"); - ret = addr_pool_insert(apool, address, (uint8)(mask ? atoi(mask) : 0)); + if (!mask) { + snprintf(error_buf, error_buf_size, + "Invalid address pool entry: %s, must be in the format of " + "ADDRESS/MASK", + addr_pool[i]); + goto fail; + } + + ret = addr_pool_insert(apool, address, (uint8)atoi(mask)); wasm_runtime_free(cp); if (!ret) { set_error_buf(error_buf, error_buf_size, diff --git a/doc/socket_api.md b/doc/socket_api.md index 9d7c88aeb..1ecc1213c 100644 --- a/doc/socket_api.md +++ b/doc/socket_api.md @@ -58,7 +58,8 @@ enabled. _iwasm_ accepts address ranges via an option, `--addr-pool`, to implement the capability control. All IP address the WebAssembly application may need to `bind()` or `connect()` -should be announced first. Every IP address should be in CIDR notation. +should be announced first. Every IP address should be in CIDR notation. If not, _iwasm_ will return +an error. ```bash $ iwasm --addr-pool=1.2.3.4/15,2.3.4.6/16 socket_example.wasm diff --git a/product-mini/platforms/common/libc_wasi.c b/product-mini/platforms/common/libc_wasi.c index b0f86e5f4..51255f7ac 100644 --- a/product-mini/platforms/common/libc_wasi.c +++ b/product-mini/platforms/common/libc_wasi.c @@ -45,7 +45,7 @@ libc_wasi_print_help(void) "path, for example:\n"); printf(" --map-dir= " "--map-dir=\n"); - printf(" --addr-pool= Grant wasi access to the given network " + printf(" --addr-pool= Grant wasi access to the given network " "addresses in\n"); printf(" CIDR notation to the program, separated " "with ',',\n"); diff --git a/samples/socket-api/CMakeLists.txt b/samples/socket-api/CMakeLists.txt index e68a63eb0..a68d0caba 100644 --- a/samples/socket-api/CMakeLists.txt +++ b/samples/socket-api/CMakeLists.txt @@ -171,6 +171,7 @@ set(WAMR_BUILD_JIT 0) set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_LIB_PTHREAD 1) +set(WAMR_BUILD_REF_TYPES 1) # compiling and linking flags if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))