]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: punycode_decode() - Fix parsing empty string [after delimiter]
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 10 Mar 2026 20:09:42 +0000 (22:09 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 11 Mar 2026 14:17:54 +0000 (14:17 +0000)
This caused an assert crash when --enable-experimental-mail-utf8 was
used and invalid punycode domain was being parsed.

Based on code by rootvector2 (Dexter.k)

src/lib/punycode.c
src/lib/test-punycode.c

index 1c8853a8b638647a74f7c568deaed16d00c318b7..c9e03a5f8d3bcec746b243405a36c6f72814e788 100644 (file)
@@ -90,6 +90,8 @@ int punycode_decode(const char *input, size_t len, string_t *output)
                ptr = delim + 1;
        else
                ptr = input;
+       if (ptr == end)
+               return -1;
 
        i_assert(ptr < end);
        while (ptr < end) {
index 485a5cfa428b81350f419dc9470ea5c935639430..f6ed829de229f6d47aee88e664db2f03775dd6ab 100644 (file)
@@ -25,6 +25,8 @@ static void test_punycode_decode(void)
                  .ret = 0 },
                /* broken */
                { .in = "zz-zzzz", .out = "", .ret = -1 },
+               { .in = "zz-", .out = "", .ret = -1 },
+               { .in = "", .out = "", .ret = -1 },
        };
 
        unsigned int i;