]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap: Don't accept strings with NULs
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 10 May 2019 16:24:51 +0000 (19:24 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 24 May 2019 08:53:54 +0000 (11:53 +0300)
IMAP doesn't allow NULs except in binary literals. We'll still allow them
in regular literals as well, but just not in strings.

This fixes a bug with unescaping a string with NULs: str_unescape() could
have been called for memory that points outside the allocated string,
causing heap corruption. This could cause crashes or theoretically even
result in remote code execution exploit.

Found by Nick Roessler and Rafi Rubin

src/lib-imap/imap-parser.c

index 05eaf7af00fff1e9181a2a546c1675ac36364717..cf2ffd9de6b9d7938170df153add06f65708e954 100644 (file)
@@ -350,6 +350,11 @@ static int imap_parser_read_string(struct imap_parser *parser,
                        break;
                }
 
+               if (data[i] == '\0') {
+                       parser->error = "NULs not allowed in strings";
+                       return FALSE;
+               }
+
                if (data[i] == '\\') {
                        if (i+1 == data_size) {
                                /* known data ends with '\' - leave it to