Skip to content

Commit 29c4d90

Browse files
committed
Use a thread-safe function and free allocated memory
1 parent c8a2956 commit 29c4d90

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

core/iwasm/common/wasm_runtime_common.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3812,7 +3812,7 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38123812

38133813
/* addr_pool(textual) -> apool */
38143814
for (i = 0; i < addr_pool_size; i++) {
3815-
char *cp, *address, *mask, *endptr;
3815+
char *cp, *address, *mask, *nextptr, *endptr;
38163816
long mask_val;
38173817
bool ret = false;
38183818

@@ -3823,14 +3823,20 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38233823
goto fail;
38243824
}
38253825

3826-
address = strtok(cp, "/");
3827-
mask = strtok(NULL, "/");
3826+
#ifdef BH_PLATFORM_WINDOWS
3827+
address = strtok_s(cp, "/", &nextptr);
3828+
mask = strtok_s(NULL, "/", &nextptr);
3829+
#else
3830+
address = strtok_r(cp, "/", &nextptr);
3831+
mask = strtok_r(NULL, "/", &nextptr);
3832+
#endif
38283833

38293834
if (!mask) {
38303835
snprintf(error_buf, error_buf_size,
38313836
"Invalid address pool entry: %s, must be in the format of "
38323837
"ADDRESS/MASK",
38333838
addr_pool[i]);
3839+
wasm_runtime_free(cp);
38343840
goto fail;
38353841
}
38363842

@@ -3840,11 +3846,13 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
38403846
if (mask == endptr || *endptr != '\0') {
38413847
snprintf(error_buf, error_buf_size,
38423848
"Invalid address pool entry: mask must be a number");
3849+
wasm_runtime_free(cp);
38433850
goto fail;
38443851
}
38453852
if (errno != 0 || mask_val < 0) {
38463853
snprintf(error_buf, error_buf_size,
38473854
"Init wasi environment failed: invalid mask number");
3855+
wasm_runtime_free(cp);
38483856
goto fail;
38493857
}
38503858

0 commit comments

Comments
 (0)