[gnome-settings-daemon/gnome-3-8] xrandr: Prevent guint32 overflow



commit ecc9aec0880a2c954d8ae58ef60e7754e108ab3c
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 29 12:21:17 2013 +0100

    xrandr: Prevent guint32 overflow
    
    Passing "9223372036854775807" (G_MAXINT64) as the timestamp will
    overflow as the timestamp is cast to a guint32 internally. Clamp
    that value instead to avoid g-s-d crashing.
    
    See https://bugzilla.redhat.com/show_bug.cgi?id=1022562
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711065

 plugins/xrandr/gsd-xrandr-manager.c |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/plugins/xrandr/gsd-xrandr-manager.c b/plugins/xrandr/gsd-xrandr-manager.c
index 9ae965c..8e6aa83 100644
--- a/plugins/xrandr/gsd-xrandr-manager.c
+++ b/plugins/xrandr/gsd-xrandr-manager.c
@@ -2176,6 +2176,16 @@ gsd_xrandr_manager_finalize (GObject *object)
         G_OBJECT_CLASS (gsd_xrandr_manager_parent_class)->finalize (object);
 }
 
+static guint32
+clamp_timestamp (gint64 timestamp)
+{
+        if (timestamp < 0)
+                return 0;
+        if (timestamp > G_MAXUINT32)
+                return G_MAXUINT32;
+        return timestamp;
+}
+
 static void
 handle_method_call_xrandr_2 (GsdXrandrManager *manager,
                              const gchar *method_name,
@@ -2192,23 +2202,23 @@ handle_method_call_xrandr_2 (GsdXrandrManager *manager,
 
                 g_variant_get (parameters, "(xx)", &parent_window_id, &timestamp);
                 if (gsd_xrandr_manager_2_apply_configuration (manager, parent_window_id,
-                                                              timestamp, &error) == FALSE) {
+                                                              clamp_timestamp(timestamp), &error) == FALSE) {
                         g_dbus_method_invocation_return_gerror (invocation, error);
                 } else {
                         g_dbus_method_invocation_return_value (invocation, NULL);
                 }
         } else if (g_strcmp0 (method_name, "VideoModeSwitch") == 0) {
                 g_variant_get (parameters, "(x)", &timestamp);
-                gsd_xrandr_manager_2_video_mode_switch (manager, timestamp, NULL);
+                gsd_xrandr_manager_2_video_mode_switch (manager, clamp_timestamp(timestamp), NULL);
                 g_dbus_method_invocation_return_value (invocation, NULL);
         } else if (g_strcmp0 (method_name, "Rotate") == 0) {
                 g_variant_get (parameters, "(x)", &timestamp);
-                gsd_xrandr_manager_2_rotate (manager, timestamp, NULL);
+                gsd_xrandr_manager_2_rotate (manager, clamp_timestamp(timestamp), NULL);
                 g_dbus_method_invocation_return_value (invocation, NULL);
         } else if (g_strcmp0 (method_name, "RotateTo") == 0) {
                 GnomeRRRotation rotation;
                 g_variant_get (parameters, "(ix)", &rotation, &timestamp);
-                gsd_xrandr_manager_2_rotate_to (manager, rotation, timestamp, NULL);
+                gsd_xrandr_manager_2_rotate_to (manager, rotation, clamp_timestamp(timestamp), NULL);
                 g_dbus_method_invocation_return_value (invocation, NULL);
         }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]