Skip to content

Reject or recover incomplete Linux environment entries instead of returning truncated values #511

Description

@LunaStev

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:

import("std::env::environ")::{env_get};
fun main() -> i32 {
    var output: array<u8, 50000>;
    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:

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA problem that causes incorrect behavior or crashes.help wantedThe issue requires extra attention or help from others.needs testingIssues that require additional testing or verification.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions