Changeset 5477:fb77465af534

Show
Ignore:
Timestamp:
2008-08-18 01:20:40 (3 months ago)
Author:
Rocco Rutte <pdmef@…>
Branch:
HEAD
Message:

Validate charset names for all charset options.
Validation is either done against mutt's table of IANA assigned names or local iconv
implementation (based on the assumption that iconv_open(charset,charset) fails if charset
is unknown to the implementation). Closes #1668.

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r5475 r5477  
     12008-08-15 11:53 -0700  Brendan Cully  <brendan@kublai.com>  (ff3fbb6a92a8) 
     2 
     3        * mutt_sasl.c: Fix type-punning warning in sasl_getprop usage 
     4 
     52008-08-15 11:41 -0700  Brendan Cully  <brendan@kublai.com>  (622ef570a7e3) 
     6 
     7        * ChangeLog, parse.c: Fix a couple of compiler warnings introduced in 
     8        [00ce81d778bf]. Make the style of mutt_parse_references more 
     9        pleasing to me. 
     10 
    1112008-07-10 09:38 -0400  Aron Griffis  <agriffis@n01se.net>  (d3ee9644765f) 
    212 
  • charset.c

    r5453 r5477  
    630630  FREE (_fc);           /* __FREE_CHECKED__ */ 
    631631} 
     632 
     633int mutt_check_charset (const char *s, int strict) 
     634{ 
     635  int i; 
     636  iconv_t cd; 
     637 
     638  if (mutt_is_utf8 (s)) 
     639    return 0; 
     640 
     641  if (!strict) 
     642    for (i = 0; PreferredMIMENames[i].key; i++) 
     643    { 
     644      if (ascii_strcasecmp (PreferredMIMENames[i].key, s) == 0 || 
     645          ascii_strcasecmp (PreferredMIMENames[i].pref, s) == 0) 
     646        return 0; 
     647    } 
     648 
     649  if ((cd = mutt_iconv_open (s, s, 0)) != (iconv_t)(-1)) 
     650  { 
     651    iconv_close (cd); 
     652    return 0; 
     653  } 
     654 
     655  return -1; 
     656} 
  • charset.h

    r4963 r5477  
    5757#define M_ICONV_HOOK_FROM 1     /* apply charset-hooks to fromcode */ 
    5858 
     59/* Check if given character set is valid (either officially assigned or 
     60 * known to local iconv implementation). If strict is non-zero, check 
     61 * against iconv only. Returns 0 if known and negative otherwise. 
     62 */ 
     63int mutt_check_charset (const char *s, int strict); 
     64 
    5965#endif /* _CHARSET_H */ 
  • init.c

    r5472 r5477  
    16831683    *p++ = '"'; 
    16841684  *p = 0; 
     1685} 
     1686 
     1687static int check_charset (struct option_t *opt, const char *val) 
     1688{ 
     1689  char *p, *q, *s = safe_strdup (val); 
     1690  int rc = 0, strict = strcmp (opt->option, "send_charset") == 0; 
     1691 
     1692  for (p = strtok_r (s, ":", &q); p; p = strtok_r (NULL, ":", &q)) 
     1693  { 
     1694    if (!*p) 
     1695      continue; 
     1696    if (mutt_check_charset (p, strict) < 0) 
     1697    { 
     1698      rc = -1; 
     1699      break; 
     1700    } 
     1701  } 
     1702 
     1703  FREE(&s); 
     1704  return rc; 
    16851705} 
    16861706 
     
    18781898          myvar_del (myvar); 
    18791899        } 
    1880         else if (DTYPE (MuttVars[idx].type) == DT_ADDR) 
    1881           rfc822_free_address ((ADDRESS **) MuttVars[idx].data); 
    1882         else 
    1883           /* MuttVars[idx].data is already 'char**' (or some 'void**') or...  
    1884            * so cast to 'void*' is okay */ 
    1885           FREE ((void *) MuttVars[idx].data);           /* __FREE_CHECKED__ */ 
    18861900 
    18871901        mutt_extract_token (tmp, s, 0); 
     1902 
    18881903        if (myvar) 
    18891904        { 
     
    18941909        else if (DTYPE (MuttVars[idx].type) == DT_PATH) 
    18951910        { 
     1911          /* MuttVars[idx].data is already 'char**' (or some 'void**') or...  
     1912           * so cast to 'void*' is okay */ 
     1913          FREE ((void *) MuttVars[idx].data);           /* __FREE_CHECKED__ */ 
     1914 
    18961915          strfcpy (scratch, tmp->data, sizeof (scratch)); 
    18971916          mutt_expand_path (scratch, sizeof (scratch)); 
     
    19001919        else if (DTYPE (MuttVars[idx].type) == DT_STR) 
    19011920        { 
     1921          if (strstr (MuttVars[idx].option, "charset") && 
     1922              check_charset (&MuttVars[idx], tmp->data) < 0) 
     1923          { 
     1924            snprintf (err->data, err->dsize, _("Invalid value for option %s: \"%s\""), 
     1925                      MuttVars[idx].option, tmp->data); 
     1926            return (-1); 
     1927          } 
     1928 
     1929          FREE ((void *) MuttVars[idx].data);           /* __FREE_CHECKED__ */ 
    19021930          *((char **) MuttVars[idx].data) = safe_strdup (tmp->data); 
    19031931          if (mutt_strcmp (MuttVars[idx].option, "charset") == 0) 
     
    19061934        else 
    19071935        { 
     1936          rfc822_free_address ((ADDRESS **) MuttVars[idx].data); 
    19081937          *((ADDRESS **) MuttVars[idx].data) = rfc822_parse_adrlist (NULL, tmp->data); 
    19091938        }