validate: Don't use glib::translate::Borrowed in safe bindings

It allows use-after-free.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1570>
This commit is contained in:
Sebastian Dröge 2024-10-22 16:34:03 +03:00 committed by GStreamer Marge Bot
parent 2251b842b2
commit d1ece4bb12

View file

@ -176,10 +176,7 @@ impl<'a> ActionParameterBuilder<'a> {
} }
} }
type ActionFunction = dyn Fn( type ActionFunction = dyn Fn(&crate::Scenario, &mut crate::ActionRef) -> Result<crate::ActionSuccess, crate::ActionError>
&crate::Scenario,
glib::translate::Borrowed<crate::Action>,
) -> Result<crate::ActionSuccess, crate::ActionError>
+ Sync + Sync
+ Send + Send
+ 'static; + 'static;
@ -201,7 +198,7 @@ impl<'a> ActionTypeBuilder<'a> {
pub fn new< pub fn new<
F: Fn( F: Fn(
&crate::Scenario, &crate::Scenario,
glib::translate::Borrowed<crate::Action>, &mut crate::ActionRef,
) -> Result<crate::ActionSuccess, crate::ActionError> ) -> Result<crate::ActionSuccess, crate::ActionError>
+ Send + Send
+ Sync + Sync
@ -325,21 +322,20 @@ impl<'a> ActionTypeBuilder<'a> {
) -> c_int { ) -> c_int {
let action_type = ffi::gst_validate_get_action_type((*action).type_); let action_type = ffi::gst_validate_get_action_type((*action).type_);
let scenario = from_glib_borrow(scenario); let scenario = from_glib_borrow(scenario);
let raction = from_glib_borrow(action);
let func: &ActionFunction = &*(gst::ffi::gst_mini_object_get_qdata( let func: &ActionFunction = &*(gst::ffi::gst_mini_object_get_qdata(
action_type as *mut gst::ffi::GstMiniObject, action_type as *mut gst::ffi::GstMiniObject,
QUARK_ACTION_TYPE_FUNC.get().unwrap().into_glib(), QUARK_ACTION_TYPE_FUNC.get().unwrap().into_glib(),
) as *const Box<ActionFunction>); ) as *const Box<ActionFunction>);
let res = (*func)(&scenario, raction); let res = (*func)(&scenario, crate::ActionRef::from_mut_ptr(action));
if let Err(crate::ActionError::Error(ref err)) = res { if let Err(crate::ActionError::Error(ref err)) = res {
scenario scenario
.dynamic_cast_ref::<crate::Reporter>() .dynamic_cast_ref::<crate::Reporter>()
.unwrap() .unwrap()
.report_action( .report_action(
&crate::Action::from_glib_none(action), &from_glib_borrow(action),
glib::Quark::from_str("scenario::execution-error"), glib::Quark::from_str("scenario::execution-error"),
err, err,
); );