Skip to content

Commit e6a045e

Browse files
committed
fix(security): resolve CodeQL alerts #36 (boxed_free null check) and #38 (use-after-drop)
1 parent 9664ccb commit e6a045e

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

  • client/react/desktop/tauri-app/src-tauri/patches/glib-0.18.5/src

client/react/desktop/tauri-app/src-tauri/patches/glib-0.18.5/src/collections/ptr_slice.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,11 +895,16 @@ impl<T: TransparentPtrType> PtrSlice<T> {
895895
while self.len > len {
896896
self.len -= 1;
897897
let p = self.ptr.as_ptr().add(self.len);
898-
ptr::drop_in_place::<T>(p as *mut T);
898+
// We must use ptr::read() -> ptr::write() -> drop() sequence here to avoid
899+
// CodeQL "Access of invalid pointer" alerts. drop_in_place() invalidates the
900+
// memory location effectively for static analysis, so writing to it afterwards
901+
// triggers a warning.
902+
let item = ptr::read(p as *mut T);
899903
ptr::write(
900904
p,
901905
ptr::null_mut(),
902906
);
907+
drop(item);
903908
}
904909
}
905910
}

client/react/desktop/tauri-app/src-tauri/patches/glib-0.18.5/src/subclass/boxed.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ pub fn register_boxed_type<T: BoxedType>() -> crate::Type {
4242
Box::into_raw(copy) as ffi::gpointer
4343
}
4444
unsafe extern "C" fn boxed_free<T: BoxedType>(v: ffi::gpointer) {
45+
if v.is_null() {
46+
return;
47+
}
4548
let v = v as *mut T;
4649
let _ = Box::from_raw(v);
4750
}

0 commit comments

Comments
 (0)