aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r--camel/camel-mime-utils.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c
index fbfbb3e5be..3d915be1f7 100644
--- a/camel/camel-mime-utils.c
+++ b/camel/camel-mime-utils.c
@@ -1255,6 +1255,8 @@ header_encode_string (const unsigned char *in)
int encoding;
GString *out;
char *outstr;
+
+ g_return_val_if_fail (g_utf8_validate (in, -1, NULL), NULL);
if (in == NULL)
return NULL;
@@ -1281,13 +1283,14 @@ header_encode_string (const unsigned char *in)
const char *newinptr;
newinptr = g_utf8_next_char (inptr);
- if (newinptr == NULL) {
+ c = g_utf8_get_char (inptr);
+ if (newinptr == NULL || !g_unichar_validate (c)) {
w(g_warning ("Invalid UTF-8 sequence encountered (pos %d, char '%c'): %s",
(inptr-in), inptr[0], in));
inptr++;
continue;
}
- c = g_utf8_get_char (inptr);
+
if (g_unichar_isspace (c) && !last_was_space) {
/* we've reached the end of a 'word' */
@@ -1427,13 +1430,15 @@ header_encode_phrase_get_words (const unsigned char *in)
const char *newinptr;
newinptr = g_utf8_next_char (inptr);
- if (newinptr == NULL) {
+ c = g_utf8_get_char (inptr);
+
+ if (!g_unichar_validate (c)) {
w(g_warning ("Invalid UTF-8 sequence encountered (pos %d, char '%c'): %s",
(inptr - in), inptr[0], in));
inptr++;
continue;
}
- c = g_utf8_get_char (inptr);
+
inptr = newinptr;
if (g_unichar_isspace (c)) {