Compare commits

...

7 Commits

Author SHA1 Message Date
linear0211
0c273e1e81
Merge 29c4d906de into 418be9dfee 2025-11-27 11:15:01 +08:00
Yosh
418be9dfee
Update link to WASI Proposals.md (#4734) 2025-11-27 08:53:59 +08:00
linear0211
29c4d906de Use a thread-safe function and free allocated memory 2025-10-28 16:12:13 +09:00
linear0211
c8a2956c4e Replace mask assignment position 2025-10-14 19:34:03 +09:00
linear0211
7c134400ae
Apply suggestions from code review
Co-authored-by: liang.he <liang.he@intel.com>
2025-10-13 16:02:48 +09:00
linear0211
02f59f10b2 Add mask validation 2025-09-12 21:00:00 +09:00
linear0211
4e99b35fe5 Ensure --addr-pool mask accepts numbers only 2025-09-11 22:05:44 +09:00
3 changed files with 38 additions and 6 deletions

View File

@ -3898,7 +3898,8 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
/* addr_pool(textual) -> apool */ /* addr_pool(textual) -> apool */
for (i = 0; i < addr_pool_size; i++) { for (i = 0; i < addr_pool_size; i++) {
char *cp, *address, *mask; char *cp, *address, *mask, *nextptr, *endptr;
long mask_val;
bool ret = false; bool ret = false;
cp = bh_strdup(addr_pool[i]); cp = bh_strdup(addr_pool[i]);
@ -3908,18 +3909,40 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
goto fail; goto fail;
} }
address = strtok(cp, "/"); #ifdef BH_PLATFORM_WINDOWS
mask = strtok(NULL, "/"); address = strtok_s(cp, "/", &nextptr);
mask = strtok_s(NULL, "/", &nextptr);
#else
address = strtok_r(cp, "/", &nextptr);
mask = strtok_r(NULL, "/", &nextptr);
#endif
if (!mask) { if (!mask) {
snprintf(error_buf, error_buf_size, snprintf(error_buf, error_buf_size,
"Invalid address pool entry: %s, must be in the format of " "Invalid address pool entry: %s, must be in the format of "
"ADDRESS/MASK", "ADDRESS/MASK",
addr_pool[i]); addr_pool[i]);
wasm_runtime_free(cp);
goto fail; goto fail;
} }
ret = addr_pool_insert(apool, address, (uint8)atoi(mask)); errno = 0;
mask_val = strtol(mask, &endptr, 10);
if (mask == endptr || *endptr != '\0') {
snprintf(error_buf, error_buf_size,
"Invalid address pool entry: mask must be a number");
wasm_runtime_free(cp);
goto fail;
}
if (errno != 0 || mask_val < 0) {
snprintf(error_buf, error_buf_size,
"Init wasi environment failed: invalid mask number");
wasm_runtime_free(cp);
goto fail;
}
ret = addr_pool_insert(apool, address, (uint8)mask_val);
wasm_runtime_free(cp); wasm_runtime_free(cp);
if (!ret) { if (!ret) {
set_error_buf(error_buf, error_buf_size, set_error_buf(error_buf, error_buf_size,

View File

@ -3105,7 +3105,6 @@ addr_pool_insert(struct addr_pool *addr_pool, const char *addr, uint8 mask)
} }
next->next = NULL; next->next = NULL;
next->mask = mask;
if (os_socket_inet_network(true, addr, &target) != BHT_OK) { if (os_socket_inet_network(true, addr, &target) != BHT_OK) {
// If parsing IPv4 fails, try IPv6 // If parsing IPv4 fails, try IPv6
@ -3116,10 +3115,20 @@ addr_pool_insert(struct addr_pool *addr_pool, const char *addr, uint8 mask)
next->type = IPv6; next->type = IPv6;
bh_memcpy_s(next->addr.ip6, sizeof(next->addr.ip6), target.ipv6, bh_memcpy_s(next->addr.ip6, sizeof(next->addr.ip6), target.ipv6,
sizeof(target.ipv6)); sizeof(target.ipv6));
if (mask > 128) {
wasm_runtime_free(next);
return false;
}
next->mask = mask;
} }
else { else {
next->type = IPv4; next->type = IPv4;
next->addr.ip4 = target.ipv4; next->addr.ip4 = target.ipv4;
if (mask > 32) {
wasm_runtime_free(next);
return false;
}
next->mask = mask;
} }
/* attach with */ /* attach with */

View File

@ -2,7 +2,7 @@
This document is intended to describe the current status of WebAssembly proposals and WASI proposals in WAMR. This document is intended to describe the current status of WebAssembly proposals and WASI proposals in WAMR.
Only track proposals that are followed in the [WebAssembly proposals](https://github.com/WebAssembly/proposals) and [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/Proposals.md). Only track proposals that are followed in the [WebAssembly proposals](https://github.com/WebAssembly/proposals) and [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/docs/Proposals.md).
Normally, the document tracks proposals that are in phase 4. However, if a proposal in an earlier phase receives support, it will be added to the list below. Normally, the document tracks proposals that are in phase 4. However, if a proposal in an earlier phase receives support, it will be added to the list below.