Maybe unsound in RLocal::new
Nessuno ha ancora preso questa issue.
- Lingua principale
- Rust
- Stelle
- 337
- Fork
- 32
- Merge medio
- 8g 17h
- PR unite (30g)
- 11
Descrizione
Hello, thank you for your contribution in this project, I am scanning the unsoundness problem in rust project.
I notice the following code:
pub struct RLocal<T: Copy> {
old_value: T,
variable: *mut T,
}
impl<T> RLocal<T>
where
T: Copy,
{
pub fn new(new_value: T, variable: *mut T) -> RLocal<T> {
unsafe {
let old_value = libr::get(variable);
libr::set(variable, new_value);
Self {
old_value,
variable,
}
}
}
}
Considering that pub mod raii, and new is also a pub function. I assume that users can directly call this function. This potential situation could result in libr::get being called to a null pointer, and might trigger undefined behavior (UB). For safety reasons, I felt it necessary to report this issue. If you have performed checks elsewhere that ensure this is safe, please don’t take offense at my raising this issue.
I suggest Several possible fixes:
- If there is no external usage for
RLocalornew, they should not marked aspub, at least itsnewshould not marked aspub newmethod should add additional check for null pointer.- mark new method as unsafe and proper doc to let users know that they should provide valid Pointers.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando il modulo pubblico raii e RLocal::new, quindi esamina i chiamanti e le assunzioni sui puntatori relative a libr::get e libr::set. Determina se l'API può ricevere un puntatore nullo o comunque non valido; il lavoro è completato quando il contratto di sicurezza o la visibilità sono inequivocabili e il percorso di comportamento indefinito segnalato è stato risolto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- rust
- Ambito
- security
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100