Skip to content

fix(io): reject NUL environment names on Node - #1451

Closed
oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/env-nul-lookup
Closed

oxura wants to merge 1 commit into
bendlang:mainfrom
oxura:fix/env-nul-lookup

Conversation

@oxura

@oxura oxura commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Closes #1449.

Change

Reject NUL-containing names in get_env.js before the own-property lookup. Node's environment proxy truncates these names even in Object.hasOwn; relying on that check alone reads the variable before the NUL. Native C already rejects the name with ENOENT, and Bun already treats it as absent.

Extend the existing get_env_own.bend regression with HOME\0suffix and assert ENOENT, not just any failure. The existing environment fixtures already require HOME to be set; no value is printed or pinned. Prototype-only keys remain rejected. Document exact-name semantics in the existing BendRT paper.

No valid-key/value changes, FFI portability changes, compiler/checker changes, or protected gate/cap edits.

Observed verification

Linux, Node 22.23.1, CLI Bun 1.3.13:

  • Actual standalone Bend consumer before: C and Bun print nul=error:2; Node incorrectly prints nul=set. Exact HOME lookup succeeds on all three.
  • After: the same consumer prints nul=error:2 on Bun and Node; native behavior is unchanged.
  • Permanent updated fixture before the patch: Node prints HOME_NUL=set, failing its expected output. After: C, Bun and Node each print the exact three expected lines (toString=unset, hasOwnProperty=unset, HOME_NUL=unset).
  • Existing exact/missing environment fixture exercised on C, Bun and Node.
  • bun gates/repo.ts: PASS: 54 / 54.
  • Existing Typst paper compiles; rendered page 4 inspected with the exact-name / NUL contract.

Local qualification only; no mini-cluster gate claim. This effect does not use bun:ffi, and its Node consumer is an actual emitted program, not a direct mock of the effect.

@oxura

oxura commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

#1450 appeared while I was verifying this fix for #1449 and contains the same production guard. Closing this duplicate so there is only one merge candidate.

The verified regression in b050ac4 additionally checks that the NUL name fails specifically with ENOENT (2), while preserving the existing prototype-key cases. The same commit documents exact-key lookup. Those pieces can be reused in #1450 if useful.

Our actual emitted C, Bun 1.3.13, and Node 22.23.1 consumers confirmed the original Node-only prefix lookup and the corrected failure; the existing valid/missing-name case also passed on all three. No compiler, checker, gate, or cap changes.

@oxura oxura closed this Oct 9, 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

1 participant