]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: istream-chain - Avoid NULL pointer arithmetic
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 9 Nov 2020 15:35:15 +0000 (17:35 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 9 Nov 2020 15:38:02 +0000 (17:38 +0200)
Even though it was only doing +0. Fixes:
runtime error: applying zero offset to null pointer

src/lib/istream-chain.c

index 89fc86023a82822343a4130ff9f90e03a8875ee4..e931487836ac63af0b52d14dab21719ee5d366a5 100644 (file)
@@ -181,9 +181,12 @@ static bool i_stream_chain_skip(struct chain_istream *cstream)
                bytes_skipped -= cstream->prev_stream_left;
                cstream->prev_stream_left = 0;
        }
-       stream->pos -= bytes_skipped;
-       stream->skip -= bytes_skipped;
-       stream->buffer += bytes_skipped;
+       if (bytes_skipped > 0) {
+               i_assert(stream->buffer != NULL);
+               stream->pos -= bytes_skipped;
+               stream->skip -= bytes_skipped;
+               stream->buffer += bytes_skipped;
+       }
        cstream->prev_skip = stream->skip;
        if (link == NULL || link->eof) {
                i_assert(bytes_skipped == 0);