Skip to content

Add NULL check in ns_lookup_list_search for DNS resolution#4844

Closed
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/wasi-dns-null-check
Closed

Add NULL check in ns_lookup_list_search for DNS resolution#4844
sumleo wants to merge 1 commit intobytecodealliance:mainfrom
sumleo:fix/wasi-dns-null-check

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 25, 2026

Summary

Fix a NULL pointer dereference in ns_lookup_list_search() that causes a crash when no DNS allowlist is configured.

Problem

When the WASI runtime is started without --allow-resolve, wasi_ctx->ns_lookup_list is NULL. When a guest WASM module calls sock_addr_resolve, the call chain eventually reaches ns_lookup_list_search() in posix.c, which dereferences the list parameter unconditionally at while (*list) (line 77). This causes a segmentation fault.

Fix

Add a NULL check for the list parameter before the while (*list) loop. If list is NULL (no DNS allowlist configured), the function returns false, correctly denying the DNS lookup without crashing.

Test

Verified that without --allow-resolve, calling sock_addr_resolve from a WASM module no longer crashes the runtime and instead returns an appropriate error.

When no DNS allowlist is configured via --allow-resolve,
wasi_ctx->ns_lookup_list is NULL. This NULL pointer gets passed
to ns_lookup_list_search which dereferences it unconditionally
at the while (*list) loop, causing a crash. A guest WASM module
can trigger this by calling sock_addr_resolve.
{
size_t host_len = strlen(host), suffix_len;

if (!list)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good practice on defensive programing skills.

But WAMR tends to use a caller-guarantee policy. Caller should make sure their inputs are correct. In this case, wash-app should check inputs before uses Wasm/WASI APIs.

Therefore, I tend to reject this PR.

@sumleo
Copy link
Contributor Author

sumleo commented Mar 3, 2026

Closing this PR. After considering the feedback, I agree with the caller-guarantee policy — WAMR expects callers to ensure correct inputs before using WASI APIs, so adding defensive null-checks in the sandboxed system primitives layer is not aligned with the project design philosophy. Thanks for the review.

@sumleo sumleo closed this Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants