Skip to content

Commit 5db1b59

Browse files
otaxhusdroege
andauthored
gtk: Use a 'static lifetime in EventController::set_static_name (#2056)
* fix(event_controller): set_static_name UAF fixed, name now has static lifetime * fix(event_controller): using GStr instead of str Co-authored-by: Sebastian Dröge <[email protected]> --------- Co-authored-by: Sebastian Dröge <[email protected]>
1 parent 24b27a7 commit 5db1b59

File tree

5 files changed

+34
-13
lines changed

5 files changed

+34
-13
lines changed

gtk4/Gir.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ generate = [
103103
"Gtk.EditableProperties",
104104
"Gtk.EmojiChooser",
105105
"Gtk.EntryIconPosition",
106-
"Gtk.EventController",
107106
"Gtk.EventControllerFocus",
108107
"Gtk.EventControllerMotion",
109108
"Gtk.EventControllerScrollFlags",
@@ -1174,6 +1173,14 @@ status = "generate"
11741173
rename = "entry"
11751174
manual = true # upcast to Entry
11761175

1176+
[[object]]
1177+
name = "Gtk.EventController"
1178+
status = "generate"
1179+
manual_traits = ["EventControllerExtManual"]
1180+
[[object.function]]
1181+
name = "set_static_name"
1182+
manual = true # to make use of a static lifetimed string
1183+
11771184
[[object]]
11781185
name = "Gtk.EventControllerKey"
11791186
status = "generate"

gtk4/src/auto/event_controller.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ pub trait EventControllerExt: IsA<EventController> + 'static {
142142
}
143143
}
144144

145-
#[cfg(feature = "v4_8")]
146-
#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
147-
#[doc(alias = "gtk_event_controller_set_static_name")]
148-
fn set_static_name(&self, name: Option<&str>) {
149-
unsafe {
150-
ffi::gtk_event_controller_set_static_name(
151-
self.as_ref().to_glib_none().0,
152-
name.to_glib_none().0,
153-
);
154-
}
155-
}
156-
157145
#[doc(alias = "name")]
158146
fn connect_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
159147
unsafe extern "C" fn notify_name_trampoline<

gtk4/src/event_controller.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
#[cfg(feature = "v4_8")]
4+
use glib::translate::*;
5+
6+
#[cfg(feature = "v4_8")]
7+
use crate::ffi;
8+
use crate::{prelude::*, EventController};
9+
10+
pub trait EventControllerExtManual: IsA<EventController> + 'static {
11+
#[cfg(feature = "v4_8")]
12+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_8")))]
13+
#[doc(alias = "gtk_event_controller_set_static_name")]
14+
fn set_static_name(&self, name: Option<&'static glib::GStr>) {
15+
unsafe {
16+
ffi::gtk_event_controller_set_static_name(
17+
self.as_ref().to_glib_none().0,
18+
name.to_glib_none().0,
19+
);
20+
}
21+
}
22+
}
23+
24+
impl<O: IsA<EventController>> EventControllerExtManual for O {}

gtk4/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ mod entry;
139139
mod entry_buffer;
140140
mod entry_completion;
141141
mod enums;
142+
mod event_controller;
142143
mod event_controller_key;
143144
mod expression_watch;
144145
mod file_chooser;

gtk4/src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub use crate::{
2121
editable::EditableExtManual,
2222
entry::EntryExtManual,
2323
entry_buffer::EntryBufferExtManual,
24+
event_controller::EventControllerExtManual,
2425
expression::{GObjectPropertyExpressionExt, IsExpression},
2526
file_chooser::FileChooserExtManual,
2627
font_chooser::FontChooserExtManual,

0 commit comments

Comments
 (0)