diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-08-08 08:11:29 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-08-08 08:11:29 +0800 |
commit | 511e3153b986168e7dd189b82b1878bd43b49981 (patch) | |
tree | 1cd0b896cb60e25ed5ea6cf3a8944b26b4ed4f1c /camel/camel-mime-utils.c | |
parent | a3648b5912435cb22c82cf06e137592f1100b135 (diff) | |
download | gsoc2013-evolution-511e3153b986168e7dd189b82b1878bd43b49981.tar.gz gsoc2013-evolution-511e3153b986168e7dd189b82b1878bd43b49981.tar.zst gsoc2013-evolution-511e3153b986168e7dd189b82b1878bd43b49981.zip |
Oops - outbuf pointed to alloca'd memory but we were g_free'ing it after
2002-08-07 Jeffrey Stedfast <fejj@ximian.com>
* camel-mime-utils.c (header_encode_param): Oops - outbuf pointed
to alloca'd memory but we were g_free'ing it after using
it. Instead use g_malloc for this outbuf buffer since it may be
kinda large. Also don't depend on a single byte to nul-terminate
the outbuf buffer so as to be safe with charsets such as UCS2 and
UCS4, instead keep a pointer to the end of the buffer.
svn path=/trunk/; revision=17737
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r-- | camel/camel-mime-utils.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index e594a43ed4..3dc31f04d3 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -2929,6 +2929,7 @@ header_encode_param (const unsigned char *in, gboolean *encoded) { register const unsigned char *inptr = in; unsigned char *outbuf = NULL; + const unsigned char *inend; iconv_t cd = (iconv_t) -1; const char *charset; char *outstr; @@ -2985,14 +2986,15 @@ header_encode_param (const unsigned char *in, gboolean *encoded) if (cd == (iconv_t) -1) { charset = "UTF-8"; inptr = in; + inend = inptr + strlen (in); } else { size_t inleft, outleft; const char *inbuf; char *outptr; inleft = (inptr - in); - outleft = inleft * 6 + 16 + 1; - outptr = outbuf = alloca (outleft); + outleft = inleft * 6 + 20; + outptr = outbuf = g_malloc (outleft); inbuf = in; if (e_iconv (cd, &inbuf, &inleft, &outptr, &outleft) == (size_t) -1) { @@ -3003,16 +3005,15 @@ header_encode_param (const unsigned char *in, gboolean *encoded) e_iconv_close (cd); - *outptr = '\0'; - inptr = outbuf; + inend = outptr; } /* FIXME: set the 'language' as well, assuming we can get that info...? */ out = g_string_new (""); g_string_sprintfa (out, "%s''", charset); - while (inptr && *inptr) { + while (inptr < inend) { unsigned char c = *inptr++; /* FIXME: make sure that '\'', '*', and ';' are also encoded */ |