Skip to content

Add NULL check in ns_lookup_list_search for DNS resolution#4844

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

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.
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.

1 participant