Skip to content

Validate path copy destinations before writing #753

Closed

Description

@LunaStev

Problem

The bounded path copy helpers do not validate null destination pointers before writing. path_basename_copy(null, 8, "x") crashes instead of returning a normal failure result.

Starting points: std/path/copy.wave.

Reproduction

Tested at 6257ba3eb4b9f1ab6c247a920c6e0c4b5d699331 on Linux amd64 with LLVM 21.1.8 and a compiler built from that checkout. Build it with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --jobs 2.

For a self-contained test against this checkout's std, create a temporary alias (leaving installed std unchanged):

python3 - <<'PYSETUP'
from pathlib import Path
import shutil
p = Path('/tmp/wave-issue-std')
shutil.copytree('std', p, dirs_exist_ok=True)
for f in p.rglob('*.wave'):
    f.write_text(f.read_text().replace('"std::', '"checkout_std::'))
PYSETUP

Save as repro.wave:

import("checkout_std::path::copy")::{path_basename_copy}; fun main() -> i32 { return path_basename_copy(null, 8, "x"); }
target/debug/wavec build repro.wave --dep checkout_std=/tmp/wave-issue-std -O0 --emit=ir,bin --out-dir /tmp/wave-issue-O0
/tmp/wave-issue-O0/repro
target/debug/wavec build repro.wave --dep checkout_std=/tmp/wave-issue-std -O2 --emit=ir,bin --out-dir /tmp/wave-issue-O2
/tmp/wave-issue-O2/repro

Both executables terminate with SIGSEGV (subprocess return code -11). The other helper paths were identified by source inspection; they are not claimed as separately executed crash cases.

Scope

Add destination/capacity validation to path_join2, path_basename_copy and path_dirname_copy, using their existing error-return convention. This does not change the language-wide raw-pointer contract.

Difficulty: easy.

Completion criteria

  • Reject null destinations and invalid capacities without writing.
  • Cover exact-fit and insufficient-capacity destinations, including empty/root inputs.
  • Preserve normal output bytes, byte counts and NUL termination at O0/O2.

Activity

  1. added
    bug
    good first issue
    needs testing
    on Sep 25, 2026
  2. self-assigned this
    on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

buggood first issueneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions