From 14517cbca46e86fdb825a2ac6df35808290df99f Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 9 Apr 2003 22:04:33 +0000 Subject: Changed my mind a bit on how I wanted this to work. Instead of aborting on 2003-04-09 Jeffrey Stedfast * camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Changed my mind a bit on how I wanted this to work. Instead of aborting on an illegal sequence, do like we do with camel-mime-filter-charset and just skip over invalid sequences. Also, in the noop failure case, close the iconv_t so we don't leak it. svn path=/trunk/; revision=20796 --- camel/ChangeLog | 6 +++++ camel/camel-gpg-context.c | 68 +++++++++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/camel/ChangeLog b/camel/ChangeLog index 051531b8c7..f07d3c83f3 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,11 @@ 2003-04-09 Jeffrey Stedfast + * camel-gpg-context.c (gpg_ctx_get_utf8_diagnostics): Changed my + mind a bit on how I wanted this to work. Instead of aborting on an + illegal sequence, do like we do with camel-mime-filter-charset and + just skip over invalid sequences. Also, in the noop failure case, + close the iconv_t so we don't leak it. + * providers/imap/camel-imap-utils.c (imap_body_decode): Save the content size in a temp variable until after we've successfully parsed all of the body_type_1part expr. Also fixed a type-o in the diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c index 7a4098a3df..ad60f88fd3 100644 --- a/camel/camel-gpg-context.c +++ b/camel/camel-gpg-context.c @@ -428,39 +428,48 @@ gpg_ctx_get_utf8_diagnostics (struct _GpgCtx *gpg) inbuf = gpg->diagnostics->data; inleft = gpg->diagnostics->len; - outlen = (inleft * 2) + 16; - out = g_malloc (outlen + 1); + outleft = outlen = (inleft * 2) + 16; + outbuf = out = g_malloc (outlen + 1); do { - outbuf = out + converted; - outleft = outlen - converted; - converted = e_iconv (cd, &inbuf, &inleft, &outbuf, &outleft); if (converted == (size_t) -1) { - if (errno != E2BIG && errno != EINVAL) - goto fail; - } - - /* - * E2BIG There is not sufficient room at *outbuf. - * - * We just need to grow our outbuffer and try again. - */ - - converted = outbuf - out; - if (errno == E2BIG) { - outlen += inleft * 2 + 16; - out = g_realloc (out, outlen + 1); - outbuf = out + converted; + if (errno == E2BIG) { + /* + * E2BIG There is not sufficient room at *outbuf. + * + * We just need to grow our outbuffer and try again. + */ + + converted = outbuf - out; + outlen += inleft * 2 + 16; + out = g_realloc (out, outlen + 1); + outbuf = out + converted; + outleft = outlen - converted; + } else if (errno == EILSEQ) { + /* + * EILSEQ An invalid multibyte sequence has been encountered + * in the input. + * + * What we do here is eat the invalid bytes in the sequence and continue + */ + + inbuf++; + inleft--; + } else if (errno == EINVAL) { + /* + * EINVAL An incomplete multibyte sequence has been encounĀ­ + * tered in the input. + * + * We assume that this can only happen if we've run out of + * bytes for a multibyte sequence, if not we're in trouble. + */ + + break; + } else + goto noop; } - } while (errno == E2BIG && inleft > 0); - - /* - * EINVAL An incomplete multibyte sequence has been encounĀ­ - * tered in the input. - * - * We'll just have to ignore it... - */ + } while (((int) inleft) > 0); /* flush the iconv conversion */ e_iconv (cd, NULL, NULL, &outbuf, &outleft); @@ -471,9 +480,10 @@ gpg_ctx_get_utf8_diagnostics (struct _GpgCtx *gpg) return out; - fail: + noop: g_free (out); + e_iconv_close (cd); return gpg_ctx_get_diagnostics (gpg); } -- cgit v1.2.3