Reject or recover incomplete Linux environment entries instead of returning truncated values
- Dominant language
- Rust
- Stars
- 53
- Forks
- 16
- Avg merge
- 4h 22m
- Merged PRs (30d)
- 46
Description
## Reproduced problem
`env_get` reads at most 32,768 bytes into its internal environment buffer. The Linux provider performs one read of `/proc/self/environ`. If that read ends in the middle of an entry, the high-level parser treats the buffer boundary as the end of a complete value and returns success.
With an environment containing only `WAVE_AUDIT_VALUE` set to 40,000 `x` characters, this program prints `count=32751`, despite a destination large enough for the full value:
```wave
import("std::env::environ")::{env_get};
fun main() -> i32 {
var output: array;
var count: i64 = env_get("WAVE_AUDIT_VALUE", &output[0], 50000);
println("count={}", count);
return 0;
}
```
After building it as `long_env`, run the binary with a controlled environment:
```python
import subprocess
subprocess.run(["/absolute/path/to/long_env"],
env={"WAVE_AUDIT_VALUE": "x" * 40000}, check=True)
```
## Scope and acceptance
- [ ] Never return a successful value assembled from an unterminated partial environment entry.
- [ ] Support continuing/growing the read, or return an explicit capacity/read error rather than silently truncating or reporting a present key as absent.
- [ ] Handle keys after the initial 32 KiB and exact-boundary entries.
- [ ] Preserve the distinction between internal source truncation, caller destination-too-small and a genuinely missing key.
- [ ] Add controlled-environment regressions; tests must not inspect the developer's real environment.
- [ ] Keep Linux environment access through the existing raw OS path, with no libc binding workaround.
Start with `std/env/environ.wave:67-104` and `std/sys/linux/{amd64,arm64,riscv64,loong64}/env.wave`. Related #427 covers general environment boundary tests; #423 and #424 cover presence checks and integer overflow. This issue is specifically the incomplete source-read bug.
Audited on canonical master `0c67f4cc0c3946cbf708c11ef79db927ec8f054e` (same source tree as #502 head). Executable reproductions used Fedora Linux amd64, Wave `0.2.1-pre-beta-dev`, LLVM 21.1.8.
Contributor guide
Research direction
Start with std/env/environ.wave:67-104 and the Linux provider files under std/sys/linux/{amd64,arm64,riscv64,loong64}/env.wave. Reproduce the 40,000-character controlled-environment case, then inspect how short reads, boundary entries, destination capacity, and missing keys are distinguished. Add controlled-environment regressions covering keys after 32 KiB and exact-boundary entries; done means no unterminated entry is reported as a successful complete value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 65/100