[Spice-devel] [PATCH 2/2] SpiceDisplay: validate 'self' argument for public API

Jonathon Jongsma jjongsma at redhat.com
Mon Nov 4 19:08:03 CET 2013


Add defensive g_return[_val]_if_fail(SPICE_IS_DISPLAY()) to all public API
---
 gtk/spice-widget.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/gtk/spice-widget.c b/gtk/spice-widget.c
index 8b5fa59..014d2fb 100644
--- a/gtk/spice-widget.c
+++ b/gtk/spice-widget.c
@@ -662,7 +662,11 @@ spice_display_constructor(GType                  gtype,
  **/
 void spice_display_set_grab_keys(SpiceDisplay *display, SpiceGrabSequence *seq)
 {
-    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    SpiceDisplayPrivate *d;
+
+    g_return_if_fail(SPICE_IS_DISPLAY(display));
+
+    d = SPICE_DISPLAY_GET_PRIVATE(display);
     g_return_if_fail(d != NULL);
 
     if (d->grabseq) {
@@ -721,7 +725,11 @@ static LRESULT CALLBACK keyboard_hook_cb(int code, WPARAM wparam, LPARAM lparam)
  **/
 SpiceGrabSequence *spice_display_get_grab_keys(SpiceDisplay *display)
 {
-    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    SpiceDisplayPrivate *d;
+
+    g_return_val_if_fail(SPICE_IS_DISPLAY(display), NULL);
+
+    d = SPICE_DISPLAY_GET_PRIVATE(display);
     g_return_val_if_fail(d != NULL, NULL);
 
     return d->grabseq;
@@ -1406,7 +1414,7 @@ void spice_display_send_keys(SpiceDisplay *display, const guint *keyvals,
 {
     int i;
 
-    g_return_if_fail(SPICE_DISPLAY(display) != NULL);
+    g_return_if_fail(SPICE_IS_DISPLAY(display));
     g_return_if_fail(keyvals != NULL);
 
     SPICE_DEBUG("%s", __FUNCTION__);
@@ -2519,6 +2527,8 @@ SpiceDisplay* spice_display_new_with_monitor(SpiceSession *session, gint channel
  **/
 void spice_display_mouse_ungrab(SpiceDisplay *display)
 {
+    g_return_if_fail(SPICE_IS_DISPLAY(display));
+
     try_mouse_ungrab(display);
 }
 
@@ -2532,7 +2542,11 @@ void spice_display_mouse_ungrab(SpiceDisplay *display)
  **/
 void spice_display_copy_to_guest(SpiceDisplay *display)
 {
-    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    SpiceDisplayPrivate *d;
+
+    g_return_if_fail(SPICE_IS_DISPLAY(display));
+
+    d = SPICE_DISPLAY_GET_PRIVATE(display);
 
     g_return_if_fail(d->gtk_session != NULL);
 
@@ -2549,7 +2563,11 @@ void spice_display_copy_to_guest(SpiceDisplay *display)
  **/
 void spice_display_paste_from_guest(SpiceDisplay *display)
 {
-    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    SpiceDisplayPrivate *d;
+
+    g_return_if_fail(SPICE_IS_DISPLAY(display));
+
+    d = SPICE_DISPLAY_GET_PRIVATE(display);
 
     g_return_if_fail(d->gtk_session != NULL);
 
@@ -2566,11 +2584,15 @@ void spice_display_paste_from_guest(SpiceDisplay *display)
  **/
 GdkPixbuf *spice_display_get_pixbuf(SpiceDisplay *display)
 {
-    SpiceDisplayPrivate *d = SPICE_DISPLAY_GET_PRIVATE(display);
+    SpiceDisplayPrivate *d;
     GdkPixbuf *pixbuf;
     int x, y;
     guchar *src, *data, *dest;
 
+    g_return_val_if_fail(SPICE_IS_DISPLAY(display), NULL);
+
+    d = SPICE_DISPLAY_GET_PRIVATE(display);
+
     g_return_val_if_fail(d != NULL, NULL);
     /* TODO: ensure d->data has been exposed? */
     g_return_val_if_fail(d->data != NULL, NULL);
-- 
1.8.3.1



More information about the Spice-devel mailing list