andrew-d / andrew-d/tinycdb-rs

Unsound usages of unsafe implementation about c_void

Offen
#6 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C
Sterne
5
Forks
2
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.