Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Rust API: a path component with an interior NUL byte is silently truncated instead of rejected

Chiusa
#436 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Una pull request collegata è già stata integrata.

  • #437 di @cyphar — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
security

Direzione di ricerca

The truncation happens in the ToCString for OsStr conversion, which uses take_while to stop at the first NUL byte; start there and follow it into the create_file and resolve_nofollow call paths. Done means a path with an interior NUL returns an error instead of being cut short, with a regression test covering both calls. A linked open pull request (#437) already targets this, so check it before starting any work.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ToCString for OsStr builds the C string with take_while(|&c| c != b'\0'), so a Path containing a NUL is cut off at the NUL and the operation runs on the shorter path:

let tmp = tempfile::tempdir()?;
std::fs::create_dir(tmp.path().join("etc"))?;
std::fs::create_dir(tmp.path().join("data"))?;
let root = Root::open(tmp.path())?;

// Creates <tmp>/etc/file and returns Ok: the parent `etc\0x` became `etc`.
root.create_file(Path::new("etc\0x/file"), OpenFlags::O_WRONLY, &Permissions::from_mode(0o644))?;
assert!(tmp.path().join("etc/file").exists());

// Returns a handle to <tmp>/data: the name `data\0bad` became `data`.
let handle = root.resolve_nofollow(Path::new("data\0bad"))?;

This is surprising behavior compared to std::fs, cap-std, rustix etc which all validate and reject paths with NUL bytes. Users wanting to avoid this behavior are forced to wrap pathrs and reject NUL bytes themselves.

Lingua principale
Rust
Stelle
146
Fork
12
Merge medio
2g 16h
PR unite (30g)
5

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cyphar/libpathrs

Tutte le issue di cyphar/libpathrs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.