wavefnd / wavefnd/Wave

Prevent an out-of-bounds terminator write in path_dirname_copy

Open
#521 0 comments 0 reactions 0 assignees View on GitHub
bug good first issue
Dominant language
Rust
Stars
53
Forks
16
Avg merge
4h 22m
Merged PRs (30d)
46

Description

`path_dirname_copy(dst, 1, "file")` passes the `n + 1` capacity check because `path_dirname_len` returns zero. The fallback then writes both `'.'` at index 0 and a NUL at index 1. A one-byte destination is therefore insufficient despite being accepted. This affects the no-directory fallback, not ordinary nonempty directory copies.

Source evidence at the head of #520:

- [std/path/copy.wave:97](https://github.com/wavefnd/Wave/blob/2ae0a91c57fd76323124c0e4dff552adbfadbe1b/std/path/copy.wave#L97) — `pub fun path_dirname_copy`

Acceptance:

- [ ] Compute the fallback output length before checking capacity; reject insufficient capacity before any destination write.
- [ ] Add guarded-buffer cases for capacities 0, 1 and 2, empty input and a simple filename. Capacity 2 must produce a NUL-terminated dot.
- [ ] Keep root and ordinary directory results unchanged. Tests must check guard bytes, not only return values.

Audit status: identified by static source inspection; the scenarios above have not been executed during this audit. The permalink fixes the reviewed revision; this report does not claim the defect was introduced by #520.

Contributor guide

Open the contributing guide

Research direction

Start at std/path/copy.wave:97, the path_dirname_copy entry point, and inspect the capacity check and no-directory fallback. Add or run guarded-buffer cases for capacities 0, 1, and 2 with empty input and a simple filename, then verify guard bytes and that root and ordinary directory results remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.