Hi Moritz! You wrote:
> > I'm not sure what is happening, because the h->from is explicitly malloced > > in process_xover(), which is also the only place in the source (afaics) > > where any Slrn_Header_Type is malloced. > > So, the only thing I can think of is that slrn messes with the from field > > somewhere lese in the code. I'll try looking into it later today... > > Turns out I was wrong with the double free idea: [...] > I'll dig further on sunday. Could you try if the attached replacement for debian/patches/302_fallback_charset.diff fixes the problem? Thanks! -- Kind regards, +--------------------------------------------------------------------+ | Bas Zoetekouw | GPG key: 0644fab7 | |----------------------------| Fingerprint: c1f5 f24c d514 3fec 8bf6 | | [EMAIL PROTECTED] | a2b1 2bae e41f 0644 fab7 | +--------------------------------------------------------------------+
#! /bin/sh -e if [ $# -ne 1 ]; then echo >&2 "`basename $0`: script expects -patch|-unpatch as argument" exit 1 fi case "$1" in -patch) patch -f --no-backup-if-mismatch -p1 < $0;; -unpatch) patch -f --no-backup-if-mismatch -R -p1 < $0;; *) echo >&2 "`basename $0`: script expects -patch|-unpatch as argument" exit 1;; esac exit 0 @DPATCH@ diff -Naur eerst/slrn-0.9.8.1pl1/src/art.c slrn-0.9.8.1pl1/src/art.c --- art.c.eerst 2007-02-10 15:24:40.418301661 +0100 +++ slrn-0.9.8.1pl1/src/art.c 2007-02-10 15:29:38.486194048 +0100 @@ -473,6 +473,9 @@ remove_from_hash_table (h); slrn_free (h->tree_ptr); slrn_free (h->subject); +#ifdef USE_ICONV /* we've copied this string */ + if (h->from_malloced != NULL) slrn_free (h->from_malloced); +#endif slrn_free (h->date); slrn_free (h->realname); slrn_free_additional_headers (h->add_hdrs); @@ -5519,7 +5522,7 @@ static Slrn_Header_Type *process_xover (Slrn_XOver_Type *xov) { Slrn_Header_Type *h; - unsigned char *c; + char *c; h = (Slrn_Header_Type *) slrn_safe_malloc (sizeof (Slrn_Header_Type)); @@ -5527,9 +5530,33 @@ Number_Total++; #ifdef USE_ICONV - /* ok, some news client (Outlook Express *sigh*) just put unencoded + + /* Annoyingly, h->from wasn't malloced separately, but is part of the same + * buffer as h->subject (ie free()ing h->subject will also delete the memory + * space used by h->from(). That sucks, so make a copy of from, to make + * sure we can freely mess with the strings as we see fit. + * NOTE: h->from is free()ed in free_header() + */ + h->from_malloced = slrn_safe_strmalloc( h->from ); + h->from = h->from_malloced; + + /* ok, some news clients (Outlook Express *sigh*) just put unencoded * latin1/9 chars in their headers. As we don't know any charset at - * this time, replace those chars by '?' chars */ + * this time, try to translating them using the (user-specified) default + * charset, or if the user didn't specify any, replace all non-ASCII + * chars by question marks + */ + + /* if the user specified a fallback charset */ + if ( Slrn_Fallback_Input_Charset_Default == 0 ) + { + slrn_chmap_translate_string(Slrn_Fallback_Input_Charset, + Slrn_Charset, &(h->subject)); + slrn_chmap_translate_string(Slrn_Fallback_Input_Charset, + Slrn_Charset, &(h->from)); + } + else /* no fallback charset specified, so replace all high chars by ? */ + { c = h->subject; while (*c!='\0' && *c!=0x0a && *c!=0x0d) { @@ -5540,6 +5567,8 @@ { if (*c>=0x7f) *c = '?'; c++; } + } + #endif /* USE_ICONV */ #if SLRN_HAS_MIME diff -Naur eerst/slrn-0.9.8.1pl1/src/art.h slrn-0.9.8.1pl1/src/art.h --- art.h.eerst 2007-02-10 15:24:55.290425513 +0100 +++ slrn-0.9.8.1pl1/src/art.h 2007-02-10 15:26:54.530374227 +0100 @@ -84,6 +84,11 @@ #endif /* NOT SLRNPULL_CODE */ +#ifdef USE_ICONV +extern char *Slrn_Fallback_Input_Charset; +extern short int Slrn_Fallback_Input_Charset_Default; +#endif + typedef struct Slrn_Header_Line_Type { char *name; @@ -123,6 +128,9 @@ int bytes; char *subject; /* malloced separately */ char *from; +#ifdef USE_ICONV + char *from_malloced; /* malloced */ +#endif char *date; /* malloced */ char *msgid; /* pointers to above space */ char *refs; diff -Naur eerst/slrn-0.9.8.1pl1/src/chmap.c slrn-0.9.8.1pl1/src/chmap.c --- eerst/slrn-0.9.8.1pl1/src/chmap.c 2007-01-15 18:54:23.798361500 +0100 +++ slrn-0.9.8.1pl1/src/chmap.c 2007-01-15 19:01:51.939060247 +0100 @@ -75,6 +75,11 @@ #ifdef USE_ICONV +/* the user-specified fallback charset */ +char *Slrn_Fallback_Input_Charset = NULL; +/* is set to a true value if the user didn't specify an override fallback */ +short int Slrn_Fallback_Input_Charset_Default = 0; + const iconv_t ICONV_FAIL = (iconv_t) -1; /* translate the string *str_ptr from charset cs_from to charset cs_to */ @@ -92,7 +97,7 @@ /* make sure the charsets are initialized */ - if (cs_from == NULL) cs_from = ICONV_DEFAULT_CHARSET; + if (cs_from == NULL) cs_from = Slrn_Fallback_Input_Charset; if (cs_to == NULL) return *str_ptr; /* don't translate if from and to charsets are equal */ @@ -258,7 +263,7 @@ #ifdef USE_ICONV /* check if we need to translate */ if (a->charset == NULL) - charset = ICONV_DEFAULT_CHARSET; + charset = Slrn_Fallback_Input_Charset; else charset = a->charset; @@ -399,6 +404,22 @@ #if USE_ICONV iconv_t cd; + /* first set the fallback input charset to ASCII if the user hasn't + * specified it */ + if ( Slrn_Fallback_Input_Charset != NULL + && *Slrn_Fallback_Input_Charset == '\0' ) + { + free( Slrn_Fallback_Input_Charset ); + } + if ( Slrn_Fallback_Input_Charset == NULL ) + { + Slrn_Fallback_Input_Charset = malloc( 9 ); + strncpy( Slrn_Fallback_Input_Charset, "US-ASCII", 9 ); + Slrn_Fallback_Input_Charset_Default = 1; + } + + /* the rest of this function deals with the _output_ charset */ + /* use environenment for locale */ setlocale (LC_ALL, ""); diff -Naur eerst/slrn-0.9.8.1pl1/src/chmap.h slrn-0.9.8.1pl1/src/chmap.h --- eerst/slrn-0.9.8.1pl1/src/chmap.h 2007-01-15 18:54:23.798361500 +0100 +++ slrn-0.9.8.1pl1/src/chmap.h 2007-01-15 18:50:00.857329255 +0100 @@ -26,13 +26,12 @@ # undef USE_ICONV #endif -#define ICONV_DEFAULT_CHARSET "iso-8859-15" - extern int slrn_set_charset (char *); extern int slrn_chmap_fix_file (char *, int); #ifdef USE_ICONV extern char * slrn_chmap_translate_string ( char *, char *, char **); +extern char *Slrn_Fallback_Input_Charset; #endif extern void slrn_chmap_fix_body (Slrn_Article_Type *, int); extern void slrn_chmap_fix_header (Slrn_Header_Type *); diff -Naur eerst/slrn-0.9.8.1pl1/src/mime.c slrn-0.9.8.1pl1/src/mime.c --- eerst/slrn-0.9.8.1pl1/src/mime.c 2007-01-15 18:54:23.831356987 +0100 +++ slrn-0.9.8.1pl1/src/mime.c 2007-01-15 18:49:38.805345750 +0100 @@ -734,7 +734,7 @@ /* make sure we have a charset available */ if (a->charset==NULL) { - a->charset = slrn_safe_strmalloc(ICONV_DEFAULT_CHARSET); + a->charset = slrn_safe_strmalloc(Slrn_Fallback_Input_Charset); } #endif /* USE_ICONV */ diff -Naur eerst/slrn-0.9.8.1pl1/src/stamp-h1 slrn-0.9.8.1pl1/src/stamp-h1 --- eerst/slrn-0.9.8.1pl1/src/stamp-h1 1970-01-01 01:00:00.000000000 +0100 +++ slrn-0.9.8.1pl1/src/stamp-h1 2007-01-15 18:51:41.310588234 +0100 @@ -0,0 +1 @@ +timestamp for src/config.h diff -Naur eerst/slrn-0.9.8.1pl1/src/startup.c slrn-0.9.8.1pl1/src/startup.c --- eerst/slrn-0.9.8.1pl1/src/startup.c 2007-01-15 18:54:23.864352473 +0100 +++ slrn-0.9.8.1pl1/src/startup.c 2007-01-12 22:16:05.556850947 +0100 @@ -699,7 +699,9 @@ }, #if SLRN_HAS_MIME -# ifndef USE_ICONV /* this is fetched from the current locale */ +# ifdef USE_ICONV + {"fallback_charset", &Slrn_Fallback_Input_Charset}, +#else {"mime_charset", &Slrn_Mime_Display_Charset}, # endif /* USE_ICONV */ {"metamail_command", &Slrn_MetaMail_Cmd},