[Spice-devel] [spice-gtk][PATCHv2] spice-widget: Protect against a NULL window

Christophe Fergeau cfergeau at redhat.com
Tue Nov 25 05:38:26 PST 2014


Hey,

On Tue, Nov 25, 2014 at 02:28:01PM +0100, Fabiano FidĂȘncio wrote:
> Return early instead of call gtk_widget_get_window() with a NULL window,
> avoiding segfaults when running on windows using GTK3.
> 
> Program received signal SIGSEGV, Segmentation fault.
> _gdk_windows_has_impl <window=window at entry=0x0> at gdkwindow.c:584
> <gdb> bt
>  #0  _gdk_window_has_impl (window=window at entry=0x0) at gdkwindow.c:584
>  #1  0x70f02821 in gdk_win32_window_get_handle (window=0x0) at
>      gdkwindow-win32.c:3459
>  #2  0x00c759ef in update_display (display=0x1b18440) at
>      spice-widget.c:1297
>  #3  0x00c77280 in focus_in_event (widget=0x1b18440, focus=0x1b02b68) at
>      spice-widget.c:1462

Hmm, do we get a focus-in event on a widget which does not have a
GdkWindow? this seems unexpected (?)

>  #4  0x665727f5 in ?? () from C:\Program Files\VirtViewer
>      (GTK3)\bin\libgtk-3-0.dll
>  #5  0x00000000 in ?? ()

Small nit, it's not gtk_widget_get_window(NULL) which causes this crash,
but GDK_WINDOW_HWND(NULL)

The log accounts for the last hunk in this patch, what about the other
try_keyboard_grab part? Looking at focus_in_event, I guess it is the
same trace with s/update_display/try_keyboard_grab ?

Christophe

> ---
> Changes since v1:
> - Improve the commit message/shortlog
> - Use g_return_if_fail instead of g_warn_if_fail in update_display()
> ---
>  gtk/spice-widget.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
> index ae11073..23aca93 100644
> --- a/gtk/spice-widget.c
> +++ b/gtk/spice-widget.c
> @@ -701,9 +701,12 @@ SpiceGrabSequence *spice_display_get_grab_keys(SpiceDisplay *display)
>  static void try_keyboard_grab(SpiceDisplay *display)
>  {
>      GtkWidget *widget = GTK_WIDGET(display);
> +    GdkWindow *window = gtk_widget_get_window(widget);
>      SpiceDisplayPrivate *d = display->priv;
>      GdkGrabStatus status;
>  
> +    g_return_if_fail(window != NULL);
> +
>      if (g_getenv("SPICE_NOGRAB"))
>          return;
>      if (d->disable_inputs)
> @@ -731,8 +734,8 @@ static void try_keyboard_grab(SpiceDisplay *display)
>                                              GetModuleHandle(NULL), 0);
>      g_warn_if_fail(d->keyboard_hook != NULL);
>  #endif
> -    status = gdk_keyboard_grab(gtk_widget_get_window(widget), FALSE,
> -                               GDK_CURRENT_TIME);
> +
> +    status = gdk_keyboard_grab(window, FALSE, GDK_CURRENT_TIME);
>      if (status != GDK_GRAB_SUCCESS) {
>          g_warning("keyboard grab failed %d", status);
>          d->keyboard_grab_active = false;
> @@ -1294,7 +1297,17 @@ static gboolean check_for_grab_key(SpiceDisplay *display, int type, int keyval)
>  static void update_display(SpiceDisplay *display)
>  {
>  #ifdef G_OS_WIN32
> -    win32_window = display ? GDK_WINDOW_HWND(gtk_widget_get_window(GTK_WIDGET(display))) : NULL;
> +    GdkWindow *window;
> +
> +    win32_window = NULL;
> +
> +    if (display == NULL)
> +        return;
> +
> +    window = gtk_widget_get_window(GTK_WIDGET(display));
> +    g_return_if_fail (window != NULL);
> +
> +    win32_window = GDK_WINDOW_HWND(window);
>  #endif
>  }
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/spice-devel/attachments/20141125/584c97a0/attachment.sig>


More information about the Spice-devel mailing list