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

src/lib/istream-concat.c

index 95e417324453e37bc582465246e05203f25050b1..e04e77dc40679359817b83dfba94637672ad67c8 100644 (file)
@@ -128,9 +128,12 @@ static void i_stream_concat_skip(struct concat_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;
        i_stream_skip(cstream->cur_input, bytes_skipped);
 }