dovecot-2.2: lib-charset: Added more asserts to checking iconv()...

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 7 21:35:19 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/9fdbb3b220ec
changeset: 19120:9fdbb3b220ec
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Sep 08 00:34:14 2015 +0300
description:
lib-charset: Added more asserts to checking iconv() results.

diffstat:

 src/lib-charset/charset-iconv.c |  10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diffs (25 lines):

diff -r 93991734ae75 -r 9fdbb3b220ec src/lib-charset/charset-iconv.c
--- a/src/lib-charset/charset-iconv.c	Tue Sep 08 00:33:21 2015 +0300
+++ b/src/lib-charset/charset-iconv.c	Tue Sep 08 00:34:14 2015 +0300
@@ -74,15 +74,17 @@
 	ic_srcbuf = (ICONV_CONST char *) src;
 
 	if (iconv(t->cd, &ic_srcbuf, &srcleft,
-		  &ic_destbuf, &destleft) != (size_t)-1)
+		  &ic_destbuf, &destleft) != (size_t)-1) {
+		i_assert(srcleft == 0);
 		*result = CHARSET_RET_OK;
-	else if (errno == E2BIG) {
+	} else if (errno == E2BIG) {
 		/* set result just to avoid compiler warning */
 		*result = CHARSET_RET_INCOMPLETE_INPUT;
 		ret = FALSE;
-	} else if (errno == EINVAL)
+	} else if (errno == EINVAL) {
+		i_assert(srcleft <= CHARSET_MAX_PENDING_BUF_SIZE);
 		*result = CHARSET_RET_INCOMPLETE_INPUT;
-	else {
+	} else {
 		/* should be EILSEQ */
 		*result = CHARSET_RET_INVALID_INPUT;
 		ret = FALSE;


More information about the dovecot-cvs mailing list