[devhelp/f21] Backport patch to handle empty *.devhelp files (GNOME #742447)

Debarshi Ray rishi at fedoraproject.org
Wed Mar 4 10:41:38 UTC 2015


commit b45e63360a60e356074e415e6f92fa32ae7cf033
Author: Debarshi Ray <debarshir at gnome.org>
Date:   Wed Mar 4 11:41:17 2015 +0100

    Backport patch to handle empty *.devhelp files (GNOME #742447)

 devhelp-handle-empty-devhelp-files.patch | 113 +++++++++++++++++++++++++++++++
 devhelp.spec                             |   9 ++-
 2 files changed, 121 insertions(+), 1 deletion(-)
---
diff --git a/devhelp-handle-empty-devhelp-files.patch b/devhelp-handle-empty-devhelp-files.patch
new file mode 100644
index 0000000..8fd39c1
--- /dev/null
+++ b/devhelp-handle-empty-devhelp-files.patch
@@ -0,0 +1,113 @@
+From 0ad2461ede6002eab14b3becfd0bb4e5e00a3be1 Mon Sep 17 00:00:00 2001
+From: Debarshi Ray <debarshir at gnome.org>
+Date: Tue, 6 Jan 2015 16:51:54 +0100
+Subject: [PATCH 1/2] Don't crash with empty .devhelp* files
+
+Call g_markup_parse_context_end_parse after we are done reading the
+file to catch empty files among other things. This is the only method
+that raises G_MARKUP_ERROR_EMPTY, so it is particularly necessary for
+this case.
+
+It was necessary to remove parser_error_cb because we should not be
+freeing the context inside it and dh_parser_free would have done it
+for us anyway. The error callback is called from set_error_literal
+inside g_markup_parse_context_end_parse, and invalidating the context
+can lead to bad things.
+
+Construction of a DhBook instance can fail due to parsing errors, so
+be careful about that.
+
+https://bugzilla.gnome.org/show_bug.cgi?id=742447
+---
+ src/dh-book-manager.c |  2 ++
+ src/dh-parser.c       | 17 +++++------------
+ 2 files changed, 7 insertions(+), 12 deletions(-)
+
+diff --git a/src/dh-book-manager.c b/src/dh-book-manager.c
+index a8e1ad2..51110d2 100644
+--- a/src/dh-book-manager.c
++++ b/src/dh-book-manager.c
+@@ -648,6 +648,8 @@ book_manager_add_from_filepath (DhBookManager *book_manager,
+ 
+         /* Allocate new book struct */
+         book = dh_book_new (book_path);
++        if (book == NULL)
++                return;
+ 
+         /* Check if book with same path was already loaded in the manager */
+         if (g_list_find_custom (priv->books,
+diff --git a/src/dh-parser.c b/src/dh-parser.c
+index 35d3179..469da8e 100644
+--- a/src/dh-parser.c
++++ b/src/dh-parser.c
+@@ -468,17 +468,6 @@ parser_end_node_cb (GMarkupParseContext  *context,
+ 	}
+ }
+ 
+-static void
+-parser_error_cb (GMarkupParseContext *context,
+-		 GError              *error,
+-		 gpointer             user_data)
+-{
+-	DhParser *parser = user_data;
+-
+-	g_markup_parse_context_free (parser->context);
+- 	parser->context = NULL;
+-}
+-
+ static gboolean
+ parser_read_gz_file (DhParser     *parser,
+                      const gchar  *path,
+@@ -565,7 +554,6 @@ dh_parser_read_file (const gchar  *path,
+ 
+ 	parser->m_parser->start_element = parser_start_node_cb;
+ 	parser->m_parser->end_element = parser_end_node_cb;
+-	parser->m_parser->error = parser_error_cb;
+ 
+ 	parser->context = g_markup_parse_context_new (parser->m_parser, 0,
+ 						      parser, NULL);
+@@ -614,6 +602,11 @@ dh_parser_read_file (const gchar  *path,
+                                 goto exit;
+                         }
+                 }
++
++                if (!g_markup_parse_context_end_parse (parser->context, error)) {
++                        result = FALSE;
++                        goto exit;
++                }
+         }
+ 
+  exit:
+-- 
+2.1.0
+
+
+From 6cf3b4a20bc08d9c8245a14ee6abdc60620c6531 Mon Sep 17 00:00:00 2001
+From: Debarshi Ray <debarshir at gnome.org>
+Date: Tue, 20 Jan 2015 19:15:22 +0100
+Subject: [PATCH 2/2] Don't rely on the GError** passed by the caller
+
+https://bugzilla.gnome.org/show_bug.cgi?id=742447
+---
+ src/dh-parser.c | 5 ++---
+ 1 file changed, 2 insertions(+), 3 deletions(-)
+
+diff --git a/src/dh-parser.c b/src/dh-parser.c
+index 469da8e..3972f00 100644
+--- a/src/dh-parser.c
++++ b/src/dh-parser.c
+@@ -595,9 +595,8 @@ dh_parser_read_file (const gchar  *path,
+                         if (io_status == G_IO_STATUS_EOF || io_status == G_IO_STATUS_ERROR) {
+                                 break;
+                         }
+-                        g_markup_parse_context_parse (parser->context, buf,
+-                                                      bytes_read, error);
+-                        if (error != NULL && *error != NULL) {
++                        if (!g_markup_parse_context_parse (parser->context, buf,
++                                                           bytes_read, error)) {
+                                 result = FALSE;
+                                 goto exit;
+                         }
+-- 
+2.1.0
+
diff --git a/devhelp.spec b/devhelp.spec
index b8aae39..6177de7 100644
--- a/devhelp.spec
+++ b/devhelp.spec
@@ -2,7 +2,7 @@
 
 Name: devhelp
 Version: 3.14.0
-Release: 1%{?dist}
+Release: 2%{?dist}
 Epoch: 1
 License: GPLv2+
 Group: Development/Tools
@@ -11,6 +11,9 @@ URL: http://live.gnome.org/devhelp
 #VCS: git:git://git.gnome.org/devhelp
 Source: http://download.gnome.org/sources/devhelp/3.14/devhelp-%{version}.tar.xz
 
+# https://bugzilla.gnome.org/show_bug.cgi?id=742447
+Patch0: devhelp-handle-empty-devhelp-files.patch
+
 ### Dependencies ###
 
 Requires(post):   /usr/bin/gtk-update-icon-cache
@@ -41,6 +44,7 @@ into other applications such as IDEs.
 
 %prep
 %setup -q
+%patch0 -p1
 
 %build
 %configure --disable-static
@@ -103,6 +107,9 @@ gtk-update-icon-cache %{_datadir}/icons/hicolor >&/dev/null || :
 %{_libdir}/pkgconfig/*
 
 %changelog
+* Wed Mar 04 2015 Debarshi Ray <rishi at fedoraproject.org> - 1:3.14.0-2
+- Backport patch to handle empty *.devhelp files (GNOME #742447)
+
 * Mon Sep 22 2014 Kalev Lember <kalevlember at gmail.com> - 1:3.14.0-1
 - Update to 3.14.0
 


More information about the scm-commits mailing list