Changeset 5477:fb77465af534
- 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:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r5475
|
r5477
|
|
| | 1 | 2008-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 | |
| | 5 | 2008-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 | |
| 1 | 11 | 2008-07-10 09:38 -0400 Aron Griffis <agriffis@n01se.net> (d3ee9644765f) |
| 2 | 12 | |
-
|
r5453
|
r5477
|
|
| 630 | 630 | FREE (_fc); /* __FREE_CHECKED__ */ |
| 631 | 631 | } |
| | 632 | |
| | 633 | int 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 | } |
-
|
r4963
|
r5477
|
|
| 57 | 57 | #define M_ICONV_HOOK_FROM 1 /* apply charset-hooks to fromcode */ |
| 58 | 58 | |
| | 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 | */ |
| | 63 | int mutt_check_charset (const char *s, int strict); |
| | 64 | |
| 59 | 65 | #endif /* _CHARSET_H */ |
-
|
r5472
|
r5477
|
|
| 1683 | 1683 | *p++ = '"'; |
| 1684 | 1684 | *p = 0; |
| | 1685 | } |
| | 1686 | |
| | 1687 | static 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; |
| 1685 | 1705 | } |
| 1686 | 1706 | |
| … |
… |
|
| 1878 | 1898 | myvar_del (myvar); |
| 1879 | 1899 | } |
| 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__ */ |
| 1886 | 1900 | |
| 1887 | 1901 | mutt_extract_token (tmp, s, 0); |
| | 1902 | |
| 1888 | 1903 | if (myvar) |
| 1889 | 1904 | { |
| … |
… |
|
| 1894 | 1909 | else if (DTYPE (MuttVars[idx].type) == DT_PATH) |
| 1895 | 1910 | { |
| | 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 | |
| 1896 | 1915 | strfcpy (scratch, tmp->data, sizeof (scratch)); |
| 1897 | 1916 | mutt_expand_path (scratch, sizeof (scratch)); |
| … |
… |
|
| 1900 | 1919 | else if (DTYPE (MuttVars[idx].type) == DT_STR) |
| 1901 | 1920 | { |
| | 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__ */ |
| 1902 | 1930 | *((char **) MuttVars[idx].data) = safe_strdup (tmp->data); |
| 1903 | 1931 | if (mutt_strcmp (MuttVars[idx].option, "charset") == 0) |
| … |
… |
|
| 1906 | 1934 | else |
| 1907 | 1935 | { |
| | 1936 | rfc822_free_address ((ADDRESS **) MuttVars[idx].data); |
| 1908 | 1937 | *((ADDRESS **) MuttVars[idx].data) = rfc822_parse_adrlist (NULL, tmp->data); |
| 1909 | 1938 | } |