Repository navigation
fix(io): get_env rejects a name with a "=" - #1795
Merged
Merged
Conversation
glibc's getenv("A=B") matches the entry "A=B=C" and answers "C", so on the
C lane and on Node a name with a "=" read part of another variable's value,
while Bun failed. Reject such a name like one with a NUL (bendlang#1449), so every
lane answers ENOENT.
Lorenzobattistela
approved these changes
Oct 21, 2026
Lorenzobattistela
left a comment
Collaborator
There was a problem hiding this comment.
Gates green merged onto main 042e797 (repo, test, ping, safe; perf matches main). Checked on macOS too: with main's effects the C and Node lanes print eq=x=y, with this PR every lane prints eq=unset, so the test discriminates on the gate's hardware.
Optional nit: macOS getenv cuts the name at the first = and answers A's whole value, not part of it, so the comments in get_env.c and the test header could say "A's value or part of it".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #1794.
IO.get_envpassed a name containing=straight to the host. glibc'sgetenv("A=B")matches the entryA=B=Cand answersC, so on the C lane and on the Node lane (whoseprocess.envusesgetenv) the call read part of another variable's value, while Bun, which looks up the exact key, failed with ENOENT. The lanes disagreed, and a name the caller built could read a variable it never named.A(withA='B=C')A=B(before)A=B(after)Done("B=C")Done("C")Fail(ENOENT)Done("B=C")Done("C")Fail(ENOENT)Done("B=C")Fail(ENOENT)Fail(ENOENT)Change
bend2/effs/get_env.c: reject a name containing=with the same ENOENT the NUL guard (io_nul) and the unset path already return, before callinggetenv.bend2/effs/get_env.js: the same check next to the NUL check from IO.get_env on Node truncates names at embedded NUL #1449.tests/io/get_env_eq.bend(+get_env_eq.c/get_env_eq.js): a foreignput_eqeffect setsBEND_ENV_EQ=x=y; the test pinsexact=x=yandeq=unsetforget_env("BEND_ENV_EQ=x").Valid names, values containing
=, own-property semantics and the error codes are unchanged: the guard only fires on a name no variable can have.Verification
On Linux x86_64 (clang 23.1.1, Bun 1.4.3, Node v26.10.0), each test checked and interpreted with
bun bend2/main.ts <t>.bend, then built with-o t.js -o t.cand run under Bun, Node and the clang binary:tests/io/get_env_eq.bendbefore the fix: interp and Bun printeq=unset, Node and C printeq=y. After: all four printexact=x=y/eq=unset. So the test discriminates the bug.tests/io/get_env.bend,get_env_nul.bend,get_env_own.bend,nul_bytes.bend: unchanged output on all four lanes.bun gates/repo.ts:PASS: 54 / 54(the new files matchtests/...andbend2/effs/[a-z0-9_]+\.(c|js); no capped file is touched).--check-onlyrefuses the test the same way it refusestests/io/exit_status.bend(it depends on a foreign effect).get_env.jsmerges cleanly with the open fix(runtime): correct JS text boundaries after the Char rewrite #1549, which edits the line above.