[nautilus] query: don't crash with empty .savedSearch files



commit 1212e12456347da601a77de013082fd1beac8463
Author: Stefano Teso <stefano teso gmail com>
Date:   Fri Feb 4 16:22:41 2011 -0500

    query: don't crash with empty .savedSearch files
    
    Be more robust against empty .savedSearch files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=601205

 libnautilus-private/nautilus-query.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/libnautilus-private/nautilus-query.c b/libnautilus-private/nautilus-query.c
index 392aea3..3a78561 100644
--- a/libnautilus-private/nautilus-query.c
+++ b/libnautilus-private/nautilus-query.c
@@ -186,6 +186,7 @@ typedef struct {
 	gboolean in_location;
 	gboolean in_mimetypes;
 	gboolean in_mimetype;
+	gboolean error;
 } ParserInfo;
 
 static void
@@ -263,6 +264,11 @@ error_cb (GMarkupParseContext *ctx,
 	  GError *err,
 	  gpointer user_data)
 {
+	ParserInfo *info;
+
+	info = (ParserInfo *) user_data;
+
+	info->error = TRUE;
 }
 
 static GMarkupParser parser = {
@@ -286,10 +292,16 @@ nautilus_query_parse_xml (char *xml, gsize xml_len)
 	
 	info.query = nautilus_query_new ();
 	info.in_text = FALSE;
+	info.error = FALSE;
 
 	ctx = g_markup_parse_context_new (&parser, 0, &info, NULL);
 	g_markup_parse_context_parse (ctx, xml, xml_len, NULL);
 
+	if (info.error) {
+		g_object_unref (info.query);
+		return NULL;
+	}
+
 	return info.query;
 }
 
@@ -307,6 +319,11 @@ nautilus_query_load (char *file)
 	
 
 	g_file_get_contents (file, &xml, &xml_len, NULL);
+
+	if (xml_len == 0) {
+		return NULL;
+	}
+
 	query = nautilus_query_parse_xml (xml, xml_len);
 	g_free (xml);
 



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