From 0669fb63cfe5c5f7a06f0f390dbb5dcc511cea2b Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 29 Apr 2019 14:57:29 +0100 Subject: [PATCH] libmutt: fix charset code for degenerate cases --- mutt/charset.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/mutt/charset.c b/mutt/charset.c index 6bbd92755..5065351c5 100644 --- a/mutt/charset.c +++ b/mutt/charset.c @@ -269,6 +269,9 @@ static const char *lookup_charset(enum LookupType type, const char *cs) */ int mutt_ch_convert_nonmime_string(char **ps) { + if (!ps) + return -1; + const char *c1 = NULL; for (const char *c = C_AssumedCharset; c; c = c1 ? c1 + 1 : 0) @@ -310,6 +313,9 @@ int mutt_ch_convert_nonmime_string(char **ps) */ void mutt_ch_canonical_charset(char *buf, size_t buflen, const char *name) { + if (!buf || !name) + return; + char in[1024], scratch[1024]; mutt_str_strfcpy(in, name, sizeof(in)); @@ -679,6 +685,9 @@ const char *mutt_ch_iconv_lookup(const char *chs) */ int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to) { + if (!s || !from || !to) + return -1; + int rc = 0; iconv_t cd = mutt_ch_iconv_open(to, from, 0); if (cd == (iconv_t) -1) @@ -713,10 +722,10 @@ int mutt_ch_check(const char *s, size_t slen, const char *from, const char *to) */ int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flags) { - iconv_t cd; - const char *repls[] = { "\357\277\275", "?", 0 }; + if (!ps) + return -1; + char *s = *ps; - int rc = 0; if (!s || !*s) return 0; @@ -724,7 +733,10 @@ int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flag if (!to || !from) return -1; - cd = mutt_ch_iconv_open(to, from, flags); + const char *repls[] = { "\357\277\275", "?", 0 }; + int rc = 0; + + iconv_t cd = mutt_ch_iconv_open(to, from, flags); if (cd == (iconv_t) -1) return -1; @@ -774,6 +786,9 @@ int mutt_ch_convert_string(char **ps, const char *from, const char *to, int flag */ bool mutt_ch_check_charset(const char *cs, bool strict) { + if (!cs) + return false; + if (mutt_ch_is_utf8(cs)) return true; @@ -841,6 +856,9 @@ struct FgetConv *mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *t */ void mutt_ch_fgetconv_close(struct FgetConv **fc) { + if (!fc || !*fc) + return; + if ((*fc)->cd != (iconv_t) -1) iconv_close((*fc)->cd); FREE(fc); @@ -920,6 +938,9 @@ int mutt_ch_fgetconv(struct FgetConv *fc) */ char *mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc) { + if (!buf) + return NULL; + size_t r; for (r = 0; (r + 1) < buflen;) { -- 2.49.0