Skip to content

Commit 02f59f1

Browse files
committed
Add mask validation
1 parent 4e99b35 commit 02f59f1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3834,13 +3834,19 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38343834
goto fail;
38353835
}
38363836

3837+
errno = 0;
38373838
mask_val = strtol(mask, &endptr, 10);
38383839

3839-
if (*endptr != '\0') {
3840+
if (mask == endptr || *endptr != '\0') {
38403841
snprintf(error_buf, error_buf_size,
38413842
"Invalid address pool entry: mask must be a number");
38423843
goto fail;
38433844
}
3845+
if (errno != 0 || mask_val < 0 || mask_val > 128) {
3846+
snprintf(error_buf, error_buf_size,
3847+
"Init wasi environment failed: invalid mask number");
3848+
goto fail;
3849+
}
38443850

38453851
ret = addr_pool_insert(apool, address, (uint8)mask_val);
38463852
wasm_runtime_free(cp);

core/iwasm/libraries/libc-wasi/sandboxed-system-primitives/src/posix.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3116,10 +3116,18 @@ addr_pool_insert(struct addr_pool *addr_pool, const char *addr, uint8 mask)
31163116
next->type = IPv6;
31173117
bh_memcpy_s(next->addr.ip6, sizeof(next->addr.ip6), target.ipv6,
31183118
sizeof(target.ipv6));
3119+
if (mask > 128) {
3120+
wasm_runtime_free(next);
3121+
return false;
3122+
}
31193123
}
31203124
else {
31213125
next->type = IPv4;
31223126
next->addr.ip4 = target.ipv4;
3127+
if (mask > 32) {
3128+
wasm_runtime_free(next);
3129+
return false;
3130+
}
31233131
}
31243132

31253133
/* attach with */

0 commit comments

Comments
 (0)