[weston,v2,6/7] text: Don't crash if a seat has no keyboard

Submitted by Derek Foreman on Dec. 8, 2014, 4:48 p.m.

Details

Message ID 1418057309-20542-1-git-send-email-derekf@osg.samsung.com
State Accepted
Commit f0aaa417484e45aaf0aa2a56f1cdaf59b7a22ad7
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Dec. 8, 2014, 4:48 p.m.
A keyboard might not be present in a seat, so check that before
dereferencing keyboard related pointers.

Also, use the keyboard pointer we set to shorten the code a little bit.

Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
---
Made the check similar to the dereference.

 src/text-backend.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/text-backend.c b/src/text-backend.c
index e50569a..4dc7179 100644
--- a/src/text-backend.c
+++ b/src/text-backend.c
@@ -755,15 +755,19 @@  input_method_context_create(struct text_input *model,
 static void
 input_method_context_end_keyboard_grab(struct input_method_context *context)
 {
-	struct weston_keyboard_grab *grab =
-		&context->input_method->seat->keyboard->input_method_grab;
-	struct weston_keyboard *keyboard = grab->keyboard;
+	struct weston_keyboard_grab *grab;
+	struct weston_keyboard *keyboard;
+
+	if (!context->input_method->seat->keyboard)
+		return;
 
-	if (!grab->keyboard)
+	grab = &context->input_method->seat->keyboard->input_method_grab;
+	keyboard = grab->keyboard;
+	if (!keyboard)
 		return;
 
-	if (grab->keyboard->grab == grab)
-		weston_keyboard_end_grab(grab->keyboard);
+	if (keyboard->grab == grab)
+		weston_keyboard_end_grab(keyboard);
 
 	keyboard->input_method_resource = NULL;
 }

Comments

Hey,

On Mon Dec 08 2014 at 5:57:04 PM Derek Foreman <derekf@osg.samsung.com>
wrote:

> A keyboard might not be present in a seat, so check that before
> dereferencing keyboard related pointers.
>
> Also, use the keyboard pointer we set to shorten the code a little bit.
>
> Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
> ---
> Made the check similar to the dereference.
>
>  src/text-backend.c | 16 ++++++++++------
>  1 file changed, 10 insertions(+), 6 deletions(-)
>

Looks good.

Regards
Jan Arne
On Mon, 15 Dec 2014 21:22:11 +0000
Jan Arne Petersen <janarne@gmail.com> wrote:

> Hey,
> 
> On Mon Dec 08 2014 at 5:57:04 PM Derek Foreman <derekf@osg.samsung.com>
> wrote:
> 
> > A keyboard might not be present in a seat, so check that before
> > dereferencing keyboard related pointers.
> >
> > Also, use the keyboard pointer we set to shorten the code a little bit.
> >
> > Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
> > ---
> > Made the check similar to the dereference.
> >
> >  src/text-backend.c | 16 ++++++++++------
> >  1 file changed, 10 insertions(+), 6 deletions(-)
> >
> 
> Looks good.

Thanks for the reviews!

This pushed, thanks,
pq