[gtk+] cssprovider: Add recursion checks for @import



commit 6b66efe873edb95ab49e73fdba74d01cba3f5153
Author: Benjamin Otte <otte redhat com>
Date:   Tue Apr 12 02:50:25 2011 +0200

    cssprovider: Add recursion checks for @import
    
    This is pretty important, because otherwise recursions cause crashes.
    And if you accidentally change your theme to one that crashes on load,
    all your gonna SEGV and then on reboot, gdm tries to load the theme...

 gtk/gtkcssprovider.c |   42 ++++++++++++++++++++++++++++++++++++------
 1 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 5e0d02f..e785ed5 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1238,6 +1238,23 @@ gtk_css_scanner_get_base_url (GScanner *scanner)
   return priv->base;
 }
 
+static gboolean
+gtk_css_scanner_would_recurse (GScanner *scanner,
+                               GFile    *file)
+{
+  while (scanner)
+    {
+      GtkCssScannerPrivate *priv = scanner->user_data;
+
+      if (priv->file && g_file_equal (priv->file, file))
+        return TRUE;
+
+      scanner = priv->parent;
+    }
+
+  return FALSE;
+}
+
 static void
 gtk_css_provider_init (GtkCssProvider *css_provider)
 {
@@ -2282,12 +2299,25 @@ parse_rule (GtkCssProvider  *css_provider,
               return ';';
             }
 
-          /* FIXME: Avoid recursive importing */
-          gtk_css_provider_load_internal (css_provider,
-                                          scanner,
-                                          actual,
-                                          NULL, 0,
-                                          NULL);
+          if (gtk_css_scanner_would_recurse (scanner, actual))
+            {
+              char *path = g_file_get_path (actual);
+              gtk_css_provider_error (css_provider,
+                                      scanner,
+                                      GTK_CSS_PROVIDER_ERROR,
+                                      GTK_CSS_PROVIDER_ERROR_IMPORT,
+                                      "Loading '%s' would recurse",
+                                      path);
+              g_free (path);
+            }
+          else
+            {
+              gtk_css_provider_load_internal (css_provider,
+                                              scanner,
+                                              actual,
+                                              NULL, 0,
+                                              NULL);
+            }
 
           g_object_unref (actual);
 



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