Skip to content

Conversation

linear0211
Copy link
Contributor

The --addr-pool option previously used atoi to parse the mask value.
If non-numeric characters were included, atoi returned 0, causing the pool to unintentionally accept all IP addresses.

This change ensures the mask accepts only numeric values, preventing unexpected behavior.

@@ -3833,7 +3834,15 @@ wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
goto fail;
}

ret = addr_pool_insert(apool, address, (uint8)atoi(mask));
mask_val = strtol(mask, &endptr, 10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMU, strtol() can handle "a100" and "0x100", but how does it deal with "+100" and "-100"?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i feel addr_pool_insert is a bit awkward api as it takes addr as a string but mask as an integer. but it's another story.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the Linux man page:

The string may begin with an arbitrary amount of white space (as determined by isspace(3)) followed by a single optional '+' or '-' sign.

So, +100 and -100 are parsed as positive 100 and negative 100.

I’ll also update the code to add stricter strtol checks and enforce mask range validation in addr_pool_insert.

@lum1n0us lum1n0us added the bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs. label Sep 11, 2025
goto fail;
}

ret = addr_pool_insert(apool, address, (uint8)mask_val);
wasm_runtime_free(cp);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that cp is not freed when the execution jumps to the goto fail above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-fix Determine if this PR addresses a bug. It will be used by scripts to classify PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants