[evolution-ews] Bug #692688 - Crash in strip_html_tags()
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-ews] Bug #692688 - Crash in strip_html_tags()
- Date: Mon, 28 Jan 2013 11:27:26 +0000 (UTC)
commit 0f1d6c5125e587304de62f75b5781d068f5a0c4f
Author: Milan Crha <mcrha redhat com>
Date: Mon Jan 28 12:27:04 2013 +0100
Bug #692688 - Crash in strip_html_tags()
src/server/e-ews-item.c | 44 ++++++++++++++++++++++++++++++++++++++------
1 files changed, 38 insertions(+), 6 deletions(-)
---
diff --git a/src/server/e-ews-item.c b/src/server/e-ews-item.c
index 62c3fbc..4fa04a3 100644
--- a/src/server/e-ews-item.c
+++ b/src/server/e-ews-item.c
@@ -810,14 +810,46 @@ strip_html_tags (const gchar *html_text)
{
gssize haystack_len = strlen (html_text);
gchar *plain_text = g_malloc (haystack_len);
- gchar *start = g_strstr_len (html_text, haystack_len, "<body>"),
- *end = g_strstr_len (html_text, haystack_len, "</body>"),
+ gchar *start = g_strstr_len (html_text, haystack_len, "<body"),
+ *end = g_strstr_len (html_text, haystack_len, "</body"),
*i, *j;
- for (j = plain_text, i = start + 6; i < end; i++) {
- if (*i == '&') i = i + 6;
- if (*i == '<') while (*i != '>') i++;
- else { *j = *i; j++; }
+ if (!start || !end) {
+ g_free (plain_text);
+ return g_strdup (html_text);
+ }
+
+ i = start;
+ while (i < end && *i != '>') {
+ i++;
+ }
+
+ for (j = plain_text; i < end; i++) {
+ if (*i == '&') {
+ gchar *from = i;
+
+ while (i < end && *i != ';' && *i != '<' && *i != '>')
+ i++;
+
+ if (i >= end)
+ break;
+
+ if (*i != ';')
+ i = from;
+ else
+ continue;
+ }
+
+ if (*i == '<') {
+ while (i < end && *i != '>')
+ i++;
+
+ if (i >= end)
+ break;
+ } else {
+ *j = *i;
+ j++;
+ }
}
*j = '\0';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]