]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-charset: Added more asserts to checking iconv() results.
authorTimo Sirainen <tss@iki.fi>
Mon, 7 Sep 2015 21:34:14 +0000 (00:34 +0300)
committerTimo Sirainen <tss@iki.fi>
Mon, 7 Sep 2015 21:34:14 +0000 (00:34 +0300)
src/lib-charset/charset-iconv.c

index ca3e8be8b39f93ea8669d4df72af38fe80eb3846..431f226ac11513a429fdf90c3b77807e2edce7d8 100644 (file)
@@ -74,15 +74,17 @@ charset_to_utf8_try(struct charset_translation *t,
        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;