changeset 18499:46065d7276ab

lib-imap: imap_utf7_to_utf8() returns failure now for encoded NULs. All the callers change the string to NUL-terminated string, so the earlier behavior was just truncating the string at the encoded NUL. It's a bit safer to just return failure so in future if the callers didn't convert the string to NUL-terminated string it wouldn't be handled inconsistently in different places.
author Timo Sirainen <tss@iki.fi>
date Wed, 29 Apr 2015 17:19:34 +0200
parents c5cdf42e398a
children 4903ab967807
files src/lib-imap/imap-utf7.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-imap/imap-utf7.c	Wed Apr 29 11:33:21 2015 +0200
+++ b/src/lib-imap/imap-utf7.c	Wed Apr 29 17:19:34 2015 +0200
@@ -149,6 +149,14 @@
 	    high > UTF16_SURROGATE_HIGH_MAX) {
 		/* single byte */
 		size_t oldlen = str_len(dest);
+
+		if (high == 0) {
+			/* Encoded NUL isn't going to work in Dovecot code,
+			   even though it's technically valid. Return failure
+			   so the callers don't even get a chance to handle the
+			   NUL in the string inconsistently. */
+			return -1;
+		}
 		uni_ucs4_to_utf8_c(high, dest);
 		if (str_len(dest) - oldlen == 1) {
 			unsigned char last = str_data(dest)[oldlen];