Skip to content

fix(io): get_env rejects a name with an embedded NUL - #1450

Merged
Lorenzobattistela merged 2 commits into
bendlang:mainfrom
Yi-111-a:fix-io-get-env-nul
Oct 10, 2026
Merged

Lorenzobattistela merged 2 commits into
bendlang:mainfrom
Yi-111-a:fix-io-get-env-nul

Conversation

@Yi-111-a

@Yi-111-a Yi-111-a commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Closes #1449.

IO.get_env on the emitted Node lane treated an embedded NUL as the end of an environment-variable name. get_env.c already rejects such a name with io_nul before asking the host environment, so the C and Bun lanes answer Fail(ENOENT). Node's environment proxy instead truncates the key, so "HOME\0suffix" answered Done with HOME's value: the call read a variable the caller never named, on one lane only.

Confirmed here against main at 8578b7c, with the reproducer from the issue and the lanes run on Node and Bun:

Lane Exact HOME HOME\0suffix (before) HOME\0suffix (after)
Node Done Done Fail(ENOENT)
Bun Done Fail(ENOENT) Fail(ENOENT)

Change

  • bend2/effs/get_env.js: reject a name containing \0 with the same io_fail(2) the unset path already returns, before asking process.env. This matches get_env.c's io_nul(name, n) ? NULL : getenv(name) guard, so the lanes agree.
  • tests/io/get_env_nul.bend: a new io test pinning HOME=set and nul=unset.

Valid names, host FFI support, own-property semantics and the error-code policy are unchanged: the guard only fires on a name no lane can look up.

Verification

Reproduced the bug and confirmed the fix on this host, emitting the standalone JS program (-o out.js, which carries the shared runtime and the registered effects) and running it under both runtimes, plus the native Bun lane:

$ node out.js   # before the fix
HOME=set
nul=set         # wrong: read HOME through a name the caller never used

$ node out.js   # after the fix
HOME=set
nul=unset

$ bun run out.js
HOME=set
nul=unset

$ bun run bend2/main.ts tests/io/get_env_nul.bend   # native lane
HOME=set
nul=unset

The unpatched build of the new test emits nul=set under Node and the patched build emits nul=unset, so the test does discriminate the bug rather than passing vacuously. The sibling tests/io/get_env.bend and tests/io/get_env_own.bend still pass on the JS lane. Also ran:

  • bun run gates/repo.ts — PASS: 54 / 54 (both paths match the allow list: bend2/effs/[a-z0-9_]+\.(c|js) and tests/[a-z]+/[A-Za-z0-9_]+\.bend).
  • bend tests/io/get_env_nul.bend --check-only — ALL PROOFS CHECK.
  • bend tests/io/get_env_nul.bend --verdict — ALL PROOFS CHECK under the proven kernel.

The C lane is unchanged by this PR (get_env.c already had the guard) and is the first place the full three-lane gate will run this test, alongside Bun.

Node's environment proxy truncates a key at an embedded NUL, so
IO.get_env("HOME\0suffix") answered Done with HOME's value on the
Node lane while the C and Bun lanes failed ENOENT. get_env.c already
rejects such names with io_nul before asking the host; do the same in
get_env.js so every lane agrees.

Adds tests/io/get_env_nul.bend, which pins the failure on all lanes.

Co-authored-by: Claude Opus 4.5 <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit 1cb1648 into bendlang:main Oct 10, 2026
1 check passed
@Lorenzobattistela Lorenzobattistela mentioned this pull request Oct 13, 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.

IO.get_env on Node truncates names at embedded NUL

2 participants