Check if specified arg is out-of-range for auxiliary data

But do not check lower-bound because of undocumented behavior.
This commit is contained in:
gwenn 2024-12-07 11:10:47 +01:00
parent 5ae7b5c5db
commit 524fce5a19

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!(idx < self.len());
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!(idx < self.len());
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)