[weston] input: fix access to invalid resource

Submitted by Giulio Camuffo on Oct. 10, 2014, 8:46 p.m.

Details

Message ID 1412974010-20461-1-git-send-email-giuliocamuffo@gmail.com
State Accepted
Commit de77e32b10d4e803fdc7033e8dfc3c3216459971
Headers show

Not browsing as part of any series.

Commit Message

Giulio Camuffo Oct. 10, 2014, 8:46 p.m.
the keyboard focus surface may not have a valid resource (server side
surface or a surface surviving its client), so check if it is valid
before using it.
---
 src/input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/input.c b/src/input.c
index e765221..bc58223 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1803,7 +1803,7 @@  seat_get_keyboard(struct wl_client *client, struct wl_resource *resource,
 					   seat->keyboard->focus_serial);
 	}
 
-	if (seat->keyboard->focus &&
+	if (seat->keyboard->focus && seat->keyboard->focus->resource &&
 	    wl_resource_get_client(seat->keyboard->focus->resource) == client) {
 		struct weston_surface *surface =
 			(struct weston_surface *) seat->keyboard->focus;

Comments

Look OK,

it can not hurt to add this check in any case.

On 10 October 2014 22:46, Giulio Camuffo <giuliocamuffo@gmail.com> wrote:

> the keyboard focus surface may not have a valid resource (server side
> surface or a surface surviving its client), so check if it is valid
> before using it.
> ---
>  src/input.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/input.c b/src/input.c
> index e765221..bc58223 100644
> --- a/src/input.c
> +++ b/src/input.c
> @@ -1803,7 +1803,7 @@ seat_get_keyboard(struct wl_client *client, struct
> wl_resource *resource,
>                                            seat->keyboard->focus_serial);
>         }
>
> -       if (seat->keyboard->focus &&
> +       if (seat->keyboard->focus && seat->keyboard->focus->resource &&
>             wl_resource_get_client(seat->keyboard->focus->resource) ==
> client) {
>                 struct weston_surface *surface =
>                         (struct weston_surface *) seat->keyboard->focus;
> --
> 2.1.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
>
On Wed, 15 Oct 2014 10:19:33 +0200
Marek Chalupa <mchqwerty@gmail.com> wrote:

> Look OK,
> 
> it can not hurt to add this check in any case.

Yeah, I take that as Acked-by.

> On 10 October 2014 22:46, Giulio Camuffo <giuliocamuffo@gmail.com> wrote:
> 
> > the keyboard focus surface may not have a valid resource (server side
> > surface or a surface surviving its client), so check if it is valid
> > before using it.

Oh yeah, this can happen during a window closing animation, I suppose.

Pushed.


Thanks,
pq


> > ---
> >  src/input.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/src/input.c b/src/input.c
> > index e765221..bc58223 100644
> > --- a/src/input.c
> > +++ b/src/input.c
> > @@ -1803,7 +1803,7 @@ seat_get_keyboard(struct wl_client *client, struct
> > wl_resource *resource,
> >                                            seat->keyboard->focus_serial);
> >         }
> >
> > -       if (seat->keyboard->focus &&
> > +       if (seat->keyboard->focus && seat->keyboard->focus->resource &&
> >             wl_resource_get_client(seat->keyboard->focus->resource) ==
> > client) {
> >                 struct weston_surface *surface =
> >                         (struct weston_surface *) seat->keyboard->focus;
> > --
> > 2.1.2
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel@lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
> >