andrew-d / andrew-d/tinycdb-rs

Unsound usages of unsafe implementation about c_void

Aperta
#6 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
C
Stelle
5
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hi, I am scanning this crate in the latest version using my own static analyzer tool.

Unsafe pointer conversion is found at:
```rust
pub fn add(&mut self, key: &[u8], val: &[u8]) -> CdbResult<()> {
let res = unsafe {
ffi::cdb_make_add(
self.cdbm_mut_ptr(),
key.as_ptr() as *const c_void,
key.len() as c_uint,
val.as_ptr() as *const c_void,
val.len() as c_uint,
)
};
match res {
x if x < 0 => Err(CdbError::new_from_errno("Error adding key/value")),
_ => Ok(()),
}
}
```

This unsound implementation would create memory issues such as overflow, underflow, or misalignment. The attacker can manipulate the `key` and `val` arguments, which can lead to buffer overflow bug. This can further corrupt the C/C++ code.

This would cause [undefined behaviors](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) in Rust. I am reporting this issue for your attention.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.