[gtk+/parser: 62/74] cssprovider: Add recursion checks for @import
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/parser: 62/74] cssprovider: Add recursion checks for @import
- Date: Mon, 9 May 2011 15:27:58 +0000 (UTC)
commit 4bdb3ccea6065cd375b16968413660154cc2ab1a
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 3a89715..ac8cb1b 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]