Merge pull request #1607 from gwenn/auxdata

Check if specified `arg` is out-of-range for auxiliary data
This commit is contained in:
gwenn 2024-12-07 11:39:11 +01:00 committed by GitHub
commit de7cd7c7d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -176,6 +176,11 @@ impl Context<'_> {
/// ///
/// See `https://www.sqlite.org/c3ref/get_auxdata.html` for a discussion of /// See `https://www.sqlite.org/c3ref/get_auxdata.html` for a discussion of
/// this feature, or the unit tests of this module for an example. /// this feature, or the unit tests of this module for an example.
///
/// # Failure
///
/// Will panic if `arg` is greater than or equal to
/// [`self.len()`](Context::len).
pub fn get_or_create_aux<T, E, F>(&self, arg: c_int, func: F) -> Result<Arc<T>> pub fn get_or_create_aux<T, E, F>(&self, arg: c_int, func: F) -> Result<Arc<T>>
where where
T: Send + Sync + 'static, T: Send + Sync + 'static,
@ -196,7 +201,13 @@ impl Context<'_> {
/// Sets the auxiliary data associated with a particular parameter. See /// Sets the auxiliary data associated with a particular parameter. See
/// `https://www.sqlite.org/c3ref/get_auxdata.html` for a discussion of /// `https://www.sqlite.org/c3ref/get_auxdata.html` for a discussion of
/// this feature, or the unit tests of this module for an example. /// this feature, or the unit tests of this module for an example.
///
/// # Failure
///
/// Will panic if `arg` is greater than or equal to
/// [`self.len()`](Context::len).
pub fn set_aux<T: Send + Sync + 'static>(&self, arg: c_int, value: T) -> Result<Arc<T>> { pub fn set_aux<T: Send + Sync + 'static>(&self, arg: c_int, value: T) -> Result<Arc<T>> {
assert!(arg < self.len() as i32);
let orig: Arc<T> = Arc::new(value); let orig: Arc<T> = Arc::new(value);
let inner: AuxInner = orig.clone(); let inner: AuxInner = orig.clone();
let outer = Box::new(inner); let outer = Box::new(inner);
@ -216,7 +227,13 @@ impl Context<'_> {
/// [`set_aux`](Context::set_aux). Returns `Ok(None)` if no data has been /// [`set_aux`](Context::set_aux). Returns `Ok(None)` if no data has been
/// associated, and Ok(Some(v)) if it has. Returns an error if the /// associated, and Ok(Some(v)) if it has. Returns an error if the
/// requested type does not match. /// requested type does not match.
///
/// # Failure
///
/// Will panic if `arg` is greater than or equal to
/// [`self.len()`](Context::len).
pub fn get_aux<T: Send + Sync + 'static>(&self, arg: c_int) -> Result<Option<Arc<T>>> { pub fn get_aux<T: Send + Sync + 'static>(&self, arg: c_int) -> Result<Option<Arc<T>>> {
assert!(arg < self.len() as i32);
let p = unsafe { ffi::sqlite3_get_auxdata(self.ctx, arg) as *const AuxInner }; let p = unsafe { ffi::sqlite3_get_auxdata(self.ctx, arg) as *const AuxInner };
if p.is_null() { if p.is_null() {
Ok(None) Ok(None)