From 0ad2461ede6002eab14b3becfd0bb4e5e00a3be1 Mon Sep 17 00:00:00 2001
From: Debarshi Ray <debarshir@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@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