Skip to content

Reject MSVC companion output paths that alias compiler inputs #902

Closed

Description

@LunaStev

Problem

Explicit MSVC companion paths bypass compiler input protection. For example, /PDB:input.wave can replace a source file after a successful link. Staging makes publication transactional but does not make that destination safe.

Reproduction

Audited on Linux amd64 at 53bb5809cf32d29f5a5a9d313ffa332ea3cd4beb, whose tracked tree matches canonical master c5ab63f9eec388c75b00f5cd59eae28a45a9b39f. Compiler built with Rust 1.89.0, LLVM 21, and the checkout std; Whale is locked to 020d2a4. Executed the production staging/publish helper on Linux with synthetic linker outputs; this is not a native Windows link test:

#[path = "/path/to/Wave/src/link_outputs.rs"]
mod link_outputs;
fn main() {
    let root = std::path::Path::new("/tmp/wave-companion-audit");
    std::fs::create_dir_all(root).unwrap();
    let source = root.join("input.wave");
    std::fs::write(&source, "fun main() {}\n").unwrap();
    let image = root.join("app.exe");
    let mut args = vec![
        format!("/OUT:{}", image.display()),
        format!("/PDB:{}", source.display()),
    ];
    let pending = link_outputs::MsvcOutputs::prepare(&image, &mut args).unwrap();
    for option in ["/OUT:", "/PDB:"] {
        let path = args.iter().find_map(|a| a.strip_prefix(option)).unwrap();
        std::fs::write(path, b"LINKER OUTPUT").unwrap();
    }
    pending.commit().unwrap();
    assert_eq!(std::fs::read(&source).unwrap(), b"LINKER OUTPUT");
}

Compile the standalone probe with Rust 1.89. The original source is replaced. Source inspection of src/cli.rs confirms output guarding enumerates planned primary/emit outputs, while link_objects later passes linker arguments to src/link_outputs.rs without comparing companion destinations with inputs.

Scope

Protect /PDB, /IMPLIB (and derived .exp), /MAP, /ILK, and /MANIFESTFILE destinations against source/import/object/library inputs. Preserve final companion basenames and atomic publication from #536. Do not solve this by disabling valid companion outputs.

Completion criteria

  • Direct and filesystem aliases to protected inputs fail before linker execution/publication.
  • Safe companion outputs keep their requested names and rollback behavior.
  • Add focused temporary-file guards plus Windows amd64/arm64 link coverage.

Activity

  1. added
    bug
    help wanted
    needs testing
    os-specific bug
    on Oct 9, 2026
  2. self-assigned this
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp wantedneeds testingos-specific bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions