]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Move unnecessary shift check to mbase64_decode_to_utf8()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 13 Jan 2021 17:19:37 +0000 (19:19 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 3 Feb 2021 09:04:22 +0000 (09:04 +0000)
src/lib-imap/imap-utf7.c

index 90abbc829fa16d9e22cdd1e5e69b54f0e640b033..ba97d905519f36b92212bb8ff20e1ea1f032fd2e 100644 (file)
@@ -243,7 +243,12 @@ static int mbase64_decode_to_utf8(string_t *dest, const char **_src)
                        return -1;
        }
 
-       /* found ending '-' */
+       /* Found the ending '-'. Make sure it's not followed by unnecessary
+          shift. Note that '&' is always escaped as "&-" so it's not an
+          unnecessary shift. */
+       if (src[1] == '&' && src[2] != '-')
+               return -1;
+
        *_src = src + 1;
        return 0;
 }
@@ -274,10 +279,6 @@ int imap_utf7_to_utf8(const char *src, string_t *dest)
                        } else {
                                if (mbase64_decode_to_utf8(dest, &p) < 0)
                                        return -1;
-                               if (p[0] == '&' && p[1] != '-') {
-                                       /* &...-& */
-                                       return -1;
-                               }
                        }
                } else {
                        str_append_c(dest, *p++);