Skip to content

Commit 121232a

Browse files
authored
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.
1 parent c080aa8 commit 121232a

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3810,7 +3810,15 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38103810
address = strtok(cp, "/");
38113811
mask = strtok(NULL, "/");
38123812

3813-
ret = addr_pool_insert(apool, address, (uint8)(mask ? atoi(mask) : 0));
3813+
if (!mask) {
3814+
snprintf(error_buf, error_buf_size,
3815+
"Invalid address pool entry: %s, must be in the format of "
3816+
"ADDRESS/MASK",
3817+
addr_pool[i]);
3818+
goto fail;
3819+
}
3820+
3821+
ret = addr_pool_insert(apool, address, (uint8)atoi(mask));
38143822
wasm_runtime_free(cp);
38153823
if (!ret) {
38163824
set_error_buf(error_buf, error_buf_size,

doc/socket_api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ enabled.
5858

5959
_iwasm_ accepts address ranges via an option, `--addr-pool`, to implement
6060
the capability control. All IP address the WebAssembly application may need to `bind()` or `connect()`
61-
should be announced first. Every IP address should be in CIDR notation.
61+
should be announced first. Every IP address should be in CIDR notation. If not, _iwasm_ will return
62+
an error.
6263

6364
```bash
6465
$ iwasm --addr-pool=1.2.3.4/15,2.3.4.6/16 socket_example.wasm

product-mini/platforms/common/libc_wasi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ libc_wasi_print_help(void)
4545
"path, for example:\n");
4646
printf(" --map-dir=<guest-path1::host-path1> "
4747
"--map-dir=<guest-path2::host-path2>\n");
48-
printf(" --addr-pool=<addrs> Grant wasi access to the given network "
48+
printf(" --addr-pool=<addr/mask> Grant wasi access to the given network "
4949
"addresses in\n");
5050
printf(" CIDR notation to the program, separated "
5151
"with ',',\n");

samples/socket-api/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ set(WAMR_BUILD_JIT 0)
171171
set(WAMR_BUILD_LIBC_BUILTIN 1)
172172
set(WAMR_BUILD_LIBC_WASI 1)
173173
set(WAMR_BUILD_LIB_PTHREAD 1)
174+
set(WAMR_BUILD_REF_TYPES 1)
174175

175176
# compiling and linking flags
176177
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))

0 commit comments

Comments
 (0)