andrew-d / andrew-d/tinycdb-rs

Unsound usages of unsafe implementation about c_void

Abierto
#6 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
C
Estrellas
5
Forks
2
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.