mirror of
https://github.com/isar/rusqlite.git
synced 2025-03-28 08:16:04 +08:00
Check Rust str length before binding.
This commit is contained in:
parent
e8967388e6
commit
7b8051dc7e
@ -102,8 +102,12 @@ raw_to_impl!(c_double, sqlite3_bind_double);
|
||||
|
||||
impl<'a> ToSql for &'a str {
|
||||
unsafe fn bind_parameter(&self, stmt: *mut sqlite3_stmt, col: c_int) -> c_int {
|
||||
let length = self.len();
|
||||
if length > ::std::i32::MAX as usize {
|
||||
return ffi::SQLITE_TOOBIG;
|
||||
}
|
||||
match str_to_cstring(self) {
|
||||
Ok(c_str) => ffi::sqlite3_bind_text(stmt, col, c_str.as_ptr(), -1,
|
||||
Ok(c_str) => ffi::sqlite3_bind_text(stmt, col, c_str.as_ptr(), length as c_int,
|
||||
ffi::SQLITE_TRANSIENT()),
|
||||
Err(_) => ffi::SQLITE_MISUSE,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user