Re: [gmime-devel] Malformed name in from/to header results in hang
- From: Jeffrey Stedfast <fejj gnome org>
- To: Bastian Pfennigschmidt <bpfennigschmidt codesco com>
- Cc: gmime-devel-list gnome org
- Subject: Re: [gmime-devel] Malformed name in from/to header results in hang
- Date: Fri, 15 Jul 2011 23:09:44 -0400
Hi Bastian,
Can you try the attached patch?
Thanks,
Jeff
diff --git a/gmime/gmime-charset.c b/gmime/gmime-charset.c
index 958d1a2..6755081 100644
--- a/gmime/gmime-charset.c
+++ b/gmime/gmime-charset.c
@@ -35,6 +35,11 @@
#include <langinfo.h>
#endif
+#if defined (WIN32) || defined (__CYGWIN__)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif
+
#include "gmime-charset-map-private.h"
#include "gmime-table-private.h"
#include "gmime-charset.h"
@@ -262,17 +267,36 @@ g_mime_charset_map_init (void)
iconv_name = g_strdup (known_iconv_charsets[i].iconv_name);
g_hash_table_insert (iconv_charsets, charset, iconv_name);
}
-
+
+#ifndef WIN32
#ifdef HAVE_CODESET
- if ((locale_charset = nl_langinfo (CODESET)) && locale_charset[0])
+ if ((locale_charset = nl_langinfo (CODESET)) && locale_charset[0]) {
+#ifdef __CYGWIN__
+ /* Apparently some versions of Cygwin, nl_langinfo(CODESET)
+ * always reports US-ASCII no matter what. */
+ if (strcmp (locale_charset, "US-ASCII") != 0) {
+ /* Guess this version of Cygwin is fixed. */
+ locale_charset = g_ascii_strdown (locale_charset, -1);
+ } else {
+ /* Cannot rely on US-ASCII being accurate. */
+ locale_charset = NULL;
+ }
+#else
locale_charset = g_ascii_strdown (locale_charset, -1);
- else
+#endif
+ } else
locale_charset = NULL;
#endif
-
+
+#if 0
+ /* Apparently setlocale() is not reliable either... use getenv() instead. */
locale = setlocale (LC_ALL, NULL);
+#endif
+
+ if (!(locale = getenv ("LC_ALL")) || !locale[0])
+ locale = getenv ("LANG");
- if (!locale || !strcmp (locale, "C") || !strcmp (locale, "POSIX")) {
+ if (!locale || !locale[0] || !strcmp (locale, "C") || !strcmp (locale, "POSIX")) {
/* The locale "C" or "POSIX" is a portable locale; its
* LC_CTYPE part corresponds to the 7-bit ASCII character
* set. */
@@ -307,6 +331,9 @@ g_mime_charset_map_init (void)
locale_parse_lang (locale);
}
+#else /* WIN32 */
+ locale_charset = g_strdup_printf ("cp%u", GetACP ());
+#endif
}
diff --git a/gmime/gmime-filter-charset.c b/gmime/gmime-filter-charset.c
index 7bc5e9b..efc8f7a 100644
--- a/gmime/gmime-filter-charset.c
+++ b/gmime/gmime-filter-charset.c
@@ -152,7 +152,11 @@ filter_filter (GMimeFilter *filter, char *in, size_t len, size_t prespace,
if (errno == E2BIG || errno == EINVAL)
break;
- if (errno == EILSEQ) {
+ /* Note: GnuWin32's libiconv 1.9 can also set errno to ERANGE
+ * which seems to mean that it encountered a character that
+ * does not fit the specified 'from' charset. We'll handle
+ * that the same way we handle EILSEQ. */
+ if (errno == EILSEQ || errno == ERANGE) {
/*
* EILSEQ An invalid multibyte sequence has been encountered
* in the input.
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 862a9f4..86d4bac 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -1537,7 +1537,11 @@ charset_convert (iconv_t cd, const char *inbuf, size_t inleft, char **outp, size
outbuf = out + rc;
}
- if (errno == EINVAL || errno == EILSEQ) {
+ /* Note: GnuWin32's libiconv 1.9 can also set errno to ERANGE
+ * which seems to mean that it encountered a character that
+ * does not fit the specified 'from' charset. We'll handle
+ * that the same way we handle EILSEQ. */
+ if (errno == EILSEQ || errno == ERANGE) {
/* invalid or incomplete multibyte
* sequence in the input buffer */
*outbuf++ = '?';
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]