Check Rust str length before binding.

This commit is contained in:
Gwenael Treguier 2015-08-06 21:15:30 +02:00
parent e8967388e6
commit 7b8051dc7e

View File

@ -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,
}